• 使用my exclipse对数据库进行操作(1)


    一.查找

    public class class1 {

     public static void main(String[] args) {   

    // TODO Auto-generated method stub         

     try {   

    //1.找到数据库,并且链接上  

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");     

    Connection conn = DriverManager.getConnection("jdbc:sqlserver://192.168.8.60;DataBaseName=School","sa","123456");  

      //3.创建数据库输出方式SQL语句

    String sql= "select [sid],[stuName],[sex],[age] from [Student]";    

     //2.取出数据库中的数据以SQL的方式

    Statement stmt= conn.createStatement();   

    //4.取出所有的数据库的数据 

     ResultSet rst = stmt.executeQuery(sql);    

    //5.将数据库中的数据一个个取出来 

    while(rst.next()){

          int one=rst.getInt("sid");

         String two= rst.getString(2);

         String three = rst.getString(3);

         int fore = rst.getInt(4);

         System.out.println("学号为:"+one+",的名字是"+two+",性别是"+three+",年龄是:"+fore);

        }

    //6.关闭数据

        if(!rst.isClosed()){

         rst.close();     

    }     if(!stmt.isClosed()){

         stmt.close();     }

        if(!conn.isClosed()){

         conn.close();     }

      } catch (ClassNotFoundException e1) {

        // TODO Auto-generated catch block     e1.printStackTrace();   

     }catch (SQLException e) {    

     // TODO Auto-generated catch block     e.printStackTrace();    }               

        }

  • 相关阅读:
    第一类斯特林数,第二类斯特林数,组合数
    P1005 矩阵取数游戏
    P4609 [FJOI2016]建筑师
    射击小游戏一03(碰撞检测)
    CCLabelAtlas 特效 自定义CCLabelTTF
    CCSpriteBatchNode cocos2dx使用
    cocos2dx plist动画
    CCSpriteBatchNode 渲染
    cocos2dx 实现翻牌效果
    cocos2dx技能冷却
  • 原文地址:https://www.cnblogs.com/zh13197490940/p/5524520.html
Copyright © 2020-2023  润新知