JDBC 操作数据库的步骤

1、加载驱动

Class.forName()

2、获取数据库连接

Connection connection = DriverManager.getConnection(url,username,password);

3、获取Statement对象,执行sql语句

Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select * from table");

4、处理执行结果

while(rs.next()){
    int id = rs.getInt("id");
    System.out.println(id);
}

5、关闭资源

//倒序关闭
rs.close();
st.close();
connection.close();

猜你喜欢

转载自blog.csdn.net/danqiu2017/article/details/79304898