如题 求大神给个查询功能的代码 做毕业设计需要 帮帮忙 下面附上添加功能的代码
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;
}
求大神帮下忙,小弟需要一个java连接sql server数据库实现查询功能的代码
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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