当前位置: 代码迷 >> Java Web开发 >> java调用存储过程返回rs.absolute(1)报错,该如何解决
  详细解决方案

java调用存储过程返回rs.absolute(1)报错,该如何解决

热度:8037   发布时间:2013-02-25 21:20:51.0
java调用存储过程返回rs.absolute(1)报错
1.package com.mypack.test;  
2.  
3.import java.sql.CallableStatement;  
4.import java.sql.Connection;  
5.import java.sql.DriverManager;  
6.import java.sql.ResultSet;  
7.import java.sql.SQLException;  
8.  
9.public class Test {  
10. public static void main(String[] args) {  
11. Connection conn = null;  
12. CallableStatement pstmt = null;  
13. ResultSet rs = null;  
14. try {  
15. Class.forName("oracle.jdbc.OracleDriver");  
16. conn = DriverManager.getConnection(  
17. "jdbc:oracle:thin:@localhost:1521:jeffrey", "scott", "tiger");  
18. pstmt = conn.prepareCall("{call sp_findemp(?,?)}",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);  
19. pstmt.setInt(1,20);  
20. pstmt.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);  
21. pstmt.execute();  
22.  
23. rs=(ResultSet) pstmt.getObject(2);  
24.  
25. rs.absolute(1);  
26. System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));  
27.  
28.  
29. } catch (ClassNotFoundException e) {  
30. e.printStackTrace();  
31. } catch (SQLException e) {  
32. e.printStackTrace();  
33. } finally {  
34. if (rs != null) {  
35. try {  
36. rs.close();  
37. } catch (SQLException e) {  
38. e.printStackTrace();  
39. }  
40. }  
41. if (pstmt != null) {  
42. try {  
43. pstmt.close();  
44. } catch (SQLException e) {  
45. e.printStackTrace();  
46. }  
47. }  
48. if (conn != null) {  
49. try {  
50. conn.close();  
51. } catch (SQLException e) {  
52. e.printStackTrace();  
53. }  
54. }  
55. }  
56. }  
57.}  
package com.mypack.test;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Test {
public static void main(String[] args) {
Connection conn = null;
CallableStatement pstmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:jeffrey", "scott", "tiger");
pstmt = conn.prepareCall("{call sp_findemp(?,?)}",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstmt.setInt(1,20);
pstmt.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
pstmt.execute();

rs=(ResultSet) pstmt.getObject(2);

rs.absolute(1);
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));


} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Tue Dec 12 20:21:13 CST 2017
  • 最近登录:Tue Dec 12 20:21:13 CST 2017
  • 最近登录:Tue Dec 12 20:21:13 CST 2017
  • 最近登录:Tue Dec 12 20:21:13 CST 2017
  • 最近登录:Tue Dec 12 20:21:13 CST 2017