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);}}}這個(gè)是把整個(gè)列表都查詢出來了我想要的是 如果我吧SQL語句改為SELECT * FROM message WHERE name=“xx”;只要求顯示出這個(gè)名字 的那條信息即可應(yīng)該怎么處理rs得到的數(shù)據(jù)集;
添加回答
舉報(bào)
0/150
提交
取消