叨叨两句
- ~
JDBC的使用步骤
1.注册驱动
2.获得连接
3.创建执行SQL语句的对象
4.执行SQL语句
5.关闭资源
public static void main(String[] args) throws SQLException {
//注册驱动
DriverManager.registerDriver(new Driver());
String url = "jdbc:mysql://localhost:3306/day10";
String user = "root";
String password = "123456";
//获得连接
Connection connection = DriverManager.getConnection(url, user, password);
//创建执行sql语句对象
Statement statement = connection.createStatement();
//执行sql,处理结果
String sql = "select *from user";
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
System.out.println(resultSet.getObject(1));
System.out.println(resultSet.getObject(2));
System.out.println(resultSet.getObject(3));
System.out.println(resultSet.getObject(4));
}
//关闭资源
if(resultSet != null){
resultSet.close();
}
if(statement != null){
statement .close();
}
if(connection != null){
connection.close();
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。