public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e){
e.printStackTrace();
}
try{
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
PreparedStatement stmt=conn.prepareStatement("select * from student");
ResultSet rs1=stmt.executeQuery();
while(rs1.next()){
System.out.print(rs1.getString(1));
System.out.print(rs1.getString(2));
System.out.print(rs1.getString(3));
System.out.print(rs1.getString(4));
System.out.println(rs1.getString(5));
}
}catch(SQLException e){
e.printStackTrace();
}
}
连接mysql数据库
最新推荐文章于 2015-03-17 15:46:50 发布