java第4次作业
作者:互联网
public static void main(String[] args) throws SQLException {
getconn();
String selectsql="select * from info";
(所有查询代码为:
select * from info where tel like '?%';
select * from info where sex=?;
select * from info where tel like '?%';
select * from info where sex=?;
)
Object[] obj = {};
select(selectsql,obj);
demonext();
democlose();
}
private static void democlose() throws SQLException {
resultSet.close();
pstat.close();
conn.close();
}
private static void demonext() throws SQLException {
while (resultSet.next()){
System.out.println("id="+resultSet.getString("id")
+" name="+resultSet.getString("name")
+" tel="+resultSet.getString("tel")
+" sex="+resultSet.getString("sex"));
}
}
private static void select(String selectsql,Object[] obj) throws SQLException {
pstat = conn.prepareCall(selectsql);
for (int i = 0; i < obj.length; i++) {
pstat.setObject(i+1,obj[i]);
}
resultSet =pstat.executeQuery();
}
标签:info,tel,obj,getString,resultSet,作业,java,select 来源: https://blog.csdn.net/weixin_59308991/article/details/121722092