java第4次作业

2021/12/4 22:17:56

本文主要是介绍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();
}



这篇关于java第4次作业的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程