//查询id为1的用户名密码
int id = 1;
String sql = "SELECT username,password FROM user WHERE id=?";
PrepareStatement ps = conn.prepareStatement(sql);
ps.serObject(1,id);
一、加载数据库驱动//以mysql为例Class.forName("com.mysql.jdbc.Driver");二、获取数据库连接连接数据库所需的参数private static final String UR L= "jdbc:mysql://localhost:8080/db_test";private static final String USENAME = "root";private static final String PASSWORD = "root";连接数