ITPub博客

首页 > 应用开发 > Java > Jdbc callablestatement 3

Jdbc callablestatement 3

原创 Java 作者:perfychi 时间:2014-06-21 08:43:27 0 删除 编辑
/*






*/
package test;

import java.sql.*;

public class SixJdbc {
    static final String url = "jdbc:oracle:thin:@192.168.3.211:1521:chi";
    static final String userID = "scott";
    static final String passwd = "oracle";
    Connection conn = null;
    ResultSet rs = null;
    CallableStatement  cstmt =null;
    
    public static void main(String[] args) {
        new SixJdbc().TestCallable();
    }

    public void TestCallable(){
        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection(url, userID, passwd);
            cstmt = conn.prepareCall("{?=call test1_func(?,?)}");
            cstmt.setInt(2, 11);
            cstmt.setString(3, "tom11");
            cstmt.registerOutParameter(1, Types.VARCHAR);
            cstmt.execute();
            System.out.println("USERNAME = " + cstmt.getString(1));
            cstmt.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        finally{
            if(conn!= null){
                try{conn.close();}catch(Exception ex){ex.printStackTrace();}
            }
        }
        
        }
        
    }
    

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27042095/viewspace-1190528/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-06-06

  • 博文量
    484
  • 访问量
    2975551