栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

JAVA连接数据库以及一些查询代码

JAVA连接数据库以及一些查询代码

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();
}
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/334910.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号