cmf191734907 2016-04-15 12:29 采纳率: 85.7%
浏览 1479

求大神帮下忙,小弟需要一个java连接sql server数据库实现查询功能的代码

如题 求大神给个查询功能的代码 做毕业设计需要 帮帮忙 下面附上添加功能的代码
public int Add(Client c)
{
int count=0;
try
{
con=this.getcon();
String sql=String.format("insert Client values('%s',%d,'%s','%s','%s','%s','%s',0,'%s')",
c.getName(),c.getAge(),c.getSex(),c.getTel(),c.getAddress(),c.getMail(),c.getCardID(),"111111");
ps=con.prepareStatement(sql);
count=ps.executeUpdate();
}catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeAll(con, ps, rs);
}
return count;
}

  • 写回答

5条回答

  • 胡来的右手 2016-04-15 13:11
    关注

    public ResultSet executeQuerySQL(String preparedSql,String[] param){
    Connection con= null;
    PreparedStatement pst= null;
    ResultSet rs = null;
    try {
    con= getCon(); // 得到数据库连接
    pst= con.prepareStatement(preparedSql); // 得到PreparedStatement对象
    if (param != null) {
    for (int i = 0; i < param.length; i++) {
    pst.setString(i + 1, (String) param[i]);
    }
    }
    rs = pst.executeQuery(); // 执行SQL语句
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return rs;

    }
    
    
    (PS:你大学4年都干了些什么......)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog