public int SQLInput(){
int i= 0;
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection ct = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "oracle", "123456");
Statement sm = ct.createStatement();
String sql = "insert into userinfo(name,password,dept) values("zhang","123456","00001")";
i = sm.executeUpdate(sql);
sm.close();
ct.close();
}catch(Exception e){
e.printStackTrace();
}
return i;
}
insert into userinfo(name,password,dept) values("zhang","123456","00001")这条语句在pl/sql中我试过可以用的,但是在eclipse里出现如下错:
java.sql.SQLException: 关闭的连接
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.ensureOpen(OracleStatement.java:3521)
at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1604)
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1588)
at com.ebridge.portalInit.App.ExtractSqlData(App.java:436)
at com.ebridge.portalInit.App.main(App.java:539)
求救~~~~~
------解决方案--------------------
java.sql.SQLException: 关闭的连接
应该是连接建立不成功
------解决方案--------------------
String sql = "insert into userinfo(name,password,dept) values("zhang","123456","00001")";
这代码能编译通过?
------解决方案--------------------
values("zhang","123456","00001")";
把括号里面的"" 改成'' 看看