xubc

public static void main(String[] args) {

         String usname= "root";

         String pwd = "000000";  

         String driver="com.mysql.jdbc.Driver";  

         String url = "jdbc:mysql://localhost:3306/zslm?user=root&password=000000"; //zslm是数据库名字,root是用户password//是密码

         String sql = "select * from module";  

         Connection conn = null;  

         Statement stmt = null;  

         ResultSet rs = null;  

         try {  

                           Class.forName(driver);  //加载驱动    

                           conn = DriverManager.getConnection(url); //获得连接  

                           stmt = conn.createStatement();   

                           rs = stmt.executeQuery(sql);   

                           if (rs !=null){    

                                          while(rs.next()){    

                                              System.out.println(rs.getString(1));     

                                              System.out.println(rs.getString(2));    

                                              System.out.println(rs.getDate(3));     

                                              System.out.println(rs.getString(4));     

                                              System.out.println(rs.getString(5));     

                                              System.out.println(rs.getString(6));     

                                             System.out.println(rs.getString(7));     

                                            }            

                                 }else{    

                                 System.out.println("rs是null");   

                                  }  

                                rs.close();   

                               stmt.close();   

                                 rs.close();  

        } catch (ClassNotFoundException e){   

              e.printStackTrace();  

        }catch (SQLException e) {

             e.printStackTrace();  

        }

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2021-05-16
  • 2021-10-08
  • 2021-06-13
  • 2021-09-27
  • 2021-06-11
猜你喜欢
  • 2021-11-20
  • 2022-02-08
  • 2021-11-01
  • 2021-09-10
  • 2021-11-27
  • 2022-01-01
  • 2021-10-03
相关资源
相似解决方案