package com.gingersoft.db;
import java.sql.*;
import javax.swing.JFrame;
public class Application8_1{
public static void main(String args[]){
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
try{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM message");
while(rs.next()){
String no = rs.getString(1);
String name = rs.getString(2);
String sex = rs.getString(3);
String data = rs.getString(4);
String sfees = rs.getString(5);
System.out.printf("%s", no);
System.out.printf("%s", name);
System.out.printf("%s", sex);
System.out.printf("%s", data);
System.out.printf("%s", sfees);
System.out.printf("\n");
}
con.close();
}
catch(SQLException e){
System.out.println(e);
}
}
}
这个是把整个列表都查询出来了
我想要的是 如果我吧SQL语句改为SELECT * FROM message WHERE name=“xx”;
只要求显示出这个名字 的那条信息即可
应该怎么处理rs得到的数据集;
繁星coding
肥皂起泡泡
慕斯王
相关分类