publicstaticvoidmain(String[]args){Connectionconn=null;Statementstmt=null;ResultSetrs=null;try{Class.forName("com.mysql.jdbc.Driver");conn=DriverManager.getConnection("jd...
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/xuesheng,user=root,password=root");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from student where xh = '093101'");
String xuehao = "";
String xingming = "";
while (rs.next()) {
xuehao = rs.getString("xh");
xingming = rs.getString("xm");
}
System.out.println("用户名:" + xuehao + "," +" 密码:" + xingming );
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
展开