publicResultSetQuery(StringsqlStr){Connectionconn=null;Statementst=null;ResultSetrs=null;try{conn=this.getConnection();st=conn.createStatement();System.out.println("SQL:"...
public ResultSet Query(String sqlStr)
{ Connection conn=null;
Statement st=null;
ResultSet rs=null;
try{
conn=this.getConnection();
st=conn.createStatement();
System.out.println("SQL:"+sqlStr);
rs=st.executeQuery(sqlStr);
if(rs!=null){
rs.close();
}
if(st!=null){
st.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
return rs;
}
‘’''
public static void main(String args[]) throws Exception
{
DB db=new DB();
String Str="select * from users";
ResultSet rs=db.Query(Str);
if(rs.next())
{
System.out.println(rs.getString("uname"));
}
}
展开