MySQL-如何将通过select语句从MySQL访问的数据存储到字符串中?

时间:2018-03-02 05:24:12

标签: java mysql jsp jdbc

修正 - 这是一个糟糕的问题,已删除

1 个答案:

答案 0 :(得分:0)

try{  
Class.forName("com.mysql.jdbc.Driver");  
Connection con=DriverManager.getConnection(  
"jdbc:mysql://localhost:3306/sonoo","root","root");  
//here sonoo is database name, root is username and password  
Statement stmt=con.createStatement();  
ResultSet rs=stmt.executeQuery("SELECT first_name FROM table WHERE username = '"+ userName+"';");
String fname;  
while(rs.next())  
fname=new String(rs.getString(1));
System.out.println("First Name:"+fname);  
con.close();  
}
catch(Exception e){ 
  System.out.println(e);
 }