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

当前位置:我的异常网» Java Web开发 » java调用存储过程返回rs.absolute(1)报错,该如何解决

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

www.myexceptions.net  网友分享于:2013-05-11  浏览:27次

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 {

文章评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值