java 中 PreparedStatement 拼接sql语句
2个回答
2013-07-04
展开全部
/**
* 根据顾客的ID,获得顾客的NAME
*/
public String getCustomername(String cid){
String flag=null;
Connection con=CustomerManager.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select name from customer where id='"+cid+"'";
try {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
flag=rs.getString("name");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rs!=null){
try {
rs.close();
ps.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return flag;
}
* 根据顾客的ID,获得顾客的NAME
*/
public String getCustomername(String cid){
String flag=null;
Connection con=CustomerManager.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select name from customer where id='"+cid+"'";
try {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
flag=rs.getString("name");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rs!=null){
try {
rs.close();
ps.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return flag;
}
2013-07-04
展开全部
能说具体点嘛,对症下药哦~嘻嘻
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询