packagecn.qt.jdbc;importcom.mysql.jdbc.Driver;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;publicclassjdbc01{publicstaticvoidmain(String[]args){//1.注册驱动try{// Driver dic = new Driver();DriverManager.registerDriver(newcom.mysql.jdbc.Driver());//2.获取连接Connectionconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/spring","root","123456");//3.获取操作数据库的具体数据库PreparedStatementpstm=conn.prepareStatement("select * from account");//4.执行sql,得到结果集ResultSetrs=pstm.executeQuery();//5.打印while(rs.next()){System.out.println(rs.getString("name"));}rs.close();pstm.close();conn.close();}catch(Exceptione){System.out.println(e);}}}