Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/dbone";
java.sql.Connection con = DriverManager.getConnection(url, "root",
"root");
PreparedStatement ps = con
.prepareStatement("select * from student where name =? and sex =?");
ps.setString(1, "王芳");
ps.setString(2, "女");
ResultSet rs = ps.executeQuery();
boolean flag = rs.next();
System.out.println(flag + "---");
rs.close();
ps.close();
con.close(); |
|