查询某个单条数据:
package com.kuang.lesson02;
import com.kuang.lesson02.utils.jdbcUtils;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestSelect {
public static void main(String[] args) {
Connection con=null;
Statement st=null;
ResultSet rs=null;
try {
con=jdbcUtils.getConnection ();
st=con.createStatement ();
String SQL="select * from users where id=1";
rs=st.executeQuery (SQL);
while(rs.next ())
System.out.println (rs.getString ("name"));
} catch (SQLException e) {
e.printStackTrace ();
}
finally {
jdbcUtils.release (con,st,rs);
}
}
}