为什么用preparedStatement不能往数据库插入数据,而且也没有报错
我用的是MSSQL数据库,用STATEMENT插入数据的时候正常,但是用preparedStatement就出问题了。
我的代码如下,各位大哥帮我看看
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=codesearch";
String user="sa";
String password="";
Connection conn=DriverManager.getConnection(url,user,password);
String Url="asdkjklasjdfk";
String title="(String)content.get(0)";
String body="(String)content.get(1)";
conn=DriverManager.getConnection(url,user,password);
PreparedStatement pstmt=conn.prepareStatement("insert into docInfo(title,body,URL,isNew) values (?,?,?,1)");
pstmt.setString(1,title);
pstmt.setString(2,body);
pstmt.setString(3,Url);
pstmt.executeUpdate();
pstmt.close();
conn.close();