java在连oracle的存储过程时出现 java.sql.SQLException: 出现不支持的 SQL92 标记: 1: 什么错误
importjava.sql.*;publicclassTextproce{publicstaticvoidmain(String[]args)throwsExcepti...
import java.sql.*;
public class Textproce {
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection cnn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
CallableStatement cs = cnn.prepareCall("{(call p2(?,?,?))}");
cs.registerOutParameter(3, Types.INTEGER);
cs.setInt(1, 3);
cs.setInt(2, 4);
cs.execute();
System.out.println(cs.getInt(3));
cs.close();
cnn.close();
}
} 展开
public class Textproce {
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection cnn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
CallableStatement cs = cnn.prepareCall("{(call p2(?,?,?))}");
cs.registerOutParameter(3, Types.INTEGER);
cs.setInt(1, 3);
cs.setInt(2, 4);
cs.execute();
System.out.println(cs.getInt(3));
cs.close();
cnn.close();
}
} 展开
1个回答
展开全部
加个try catch
还有你这是连接数据库,不能写在main方法中
还有你这是连接数据库,不能写在main方法中
更多追问追答
追问
我直接在main函数throws Exception 了...不会是这个错误的
追答
正确写法
public class Textproce {
private static Connection cnn;
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConn(){
try {
cnn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
CallableStatement cs = cnn.prepareCall("{(call p2(?,?,?))}");
cs.registerOutParameter(3, Types.INTEGER);
cs.setInt(1, 3);
cs.setInt(2, 4);
cs.execute();
cs.close();
cnn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return cnn;
}
public static void main(String[] args) {
Textproce.getConn();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询