使用Java往sql server2008数据库无法插入数据 5
Connectionct;PreparedStatementps;String[]addmem={“aaa”,“bb”,“vv”,“11”,“dd”,“ee”};try{...
Connection ct;
PreparedStatement ps;
String[] addmem={“aaa”,“bb”,“vv”,“11”,“dd”,“ee”};
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServer");
ct=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433","sa","0708");
ps=ct.prepareStatement("insert into masMember values(?,?,?,?,?)");
ps.setString(1, addmem[0]);
ps.setString(2, addmem[1]);
ps.setString(3, addmem[2]);
ps.setInt(4, Integer.parseInt(addmem[3]));
ps.setString(5, addmem[4]);
ps.executeUpdate();
} catch (Exception e2) {
// TODO: handle exception
}finally{
try {
if(ps!=null){
ps.close();
}
if(ct!=null){
ct.close();
}
} catch (Exception e3) {
// TODO: handle exception
}
} 展开
PreparedStatement ps;
String[] addmem={“aaa”,“bb”,“vv”,“11”,“dd”,“ee”};
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServer");
ct=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433","sa","0708");
ps=ct.prepareStatement("insert into masMember values(?,?,?,?,?)");
ps.setString(1, addmem[0]);
ps.setString(2, addmem[1]);
ps.setString(3, addmem[2]);
ps.setInt(4, Integer.parseInt(addmem[3]));
ps.setString(5, addmem[4]);
ps.executeUpdate();
} catch (Exception e2) {
// TODO: handle exception
}finally{
try {
if(ps!=null){
ps.close();
}
if(ct!=null){
ct.close();
}
} catch (Exception e3) {
// TODO: handle exception
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询