List of usage examples for java.sql CallableStatement registerOutParameter
default void registerOutParameter(String parameterName, SQLType sqlType) throws SQLException
parameterName
to the JDBC type sqlType . From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); String simpleProc = "{ call simpleproc(?) }"; CallableStatement cs = conn.prepareCall(simpleProc); cs.registerOutParameter(1, java.sql.Types.INTEGER); cs.execute();//from www . j a va2 s . c om int param1 = cs.getInt(1); System.out.println("param1=" + param1); ParameterMetaData pmeta = cs.getParameterMetaData(); if (pmeta == null) { System.out.println("Vendor does not support ParameterMetaData"); } else { System.out.println(pmeta.getParameterType(1)); } conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/*from w ww .ja va2 s . c om*/ String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); CallableStatement cs = connection.prepareCall("{? = call myfuncin(?)}"); cs.registerOutParameter(1, Types.VARCHAR); // Set the value for the IN parameter cs.setString(2, "a string"); // Execute and retrieve the returned value cs.execute(); String retValue = cs.getString(1); }
From source file:Main.java
public static void main(String[] args) throws Exception { // DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); final Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "manager"); String plsql = " declare " + " p_id varchar2(20) := null; " + " l_rc sys_refcursor;" + " begin " + " p_id := ?; " + " ? := 'input parameter was = ' || p_id;" + " open l_rc for " + " select 1 id, 'abc' name from dual; " + " ? := l_rc;" + " end;"; CallableStatement cs = c.prepareCall(plsql); cs.setString(1, "12345"); cs.registerOutParameter(2, Types.VARCHAR); // cs.registerOutParameter(3, OracleTypes.CURSOR); cs.execute();/*from w w w .jav a2 s .c om*/ System.out.println("Result = " + cs.getObject(2)); ResultSet cursorResultSet = (ResultSet) cs.getObject(3); while (cursorResultSet.next()) { System.out.println(cursorResultSet.getInt(1) + " " + cursorResultSet.getString(2)); } cs.close(); c.close(); }
From source file:CallableStmt.java
public static void main(String[] args) throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; Class.forName(driver).newInstance(); System.out.println("Connecting to database..."); String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL"; Connection conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd"); CallableStatement cstmt = conn.prepareCall("{call getEmpName (?,?)}"); cstmt.setInt(1, 111111111);//from www .ja va2s .c o m cstmt.registerOutParameter(2, java.sql.Types.VARCHAR); cstmt.execute(); String empName = cstmt.getString(2); System.out.println(empName); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; Class.forName(driver).newInstance(); System.out.println("Connecting to database..."); String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL"; Connection conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd"); CallableStatement cstmt = conn.prepareCall("{call getEmpName (?,?)}"); cstmt.setInt(1, 111111111);//from w ww .ja v a2 s . com cstmt.registerOutParameter(2, java.sql.Types.VARCHAR); cstmt.execute(); String empName = cstmt.getString(2); System.out.println(empName); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection conn = null;/*from ww w . java 2 s. c om*/ String query = "begin proc(?,?,?); end;"; CallableStatement cs = conn.prepareCall(query); cs.setString(1, "string parameter"); cs.setInt(2, 1); cs.registerOutParameter(2, Types.INTEGER); cs.registerOutParameter(3, Types.INTEGER); cs.execute(); int parm2 = cs.getInt(2); // get the result from OUTPUT #2 int parm3 = cs.getInt(3); // get the result from OUTPUT #3 }
From source file:Test.java
public static void main(String[] args) throws Exception { Connection conn = DriverManager.getConnection("...", "username", "password"); String query = "{CALL GETDATE(?,?)}"; CallableStatement callableStatement = (CallableStatement) conn.prepareCall(query); callableStatement.setInt(1, 123);//from w w w . j a v a 2 s. c o m callableStatement.registerOutParameter(1, Types.DATE); callableStatement.executeQuery(); Date date = callableStatement.getObject(2, Date.class); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);/* w ww. j a va2 s. c o m*/ String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); CallableStatement cs = connection.prepareCall("{call myprocout(?)}"); // Register the type of the OUT parameter cs.registerOutParameter(1, Types.VARCHAR); cs.execute(); String outParam = cs.getString(1); // OUT parameter System.out.println(outParam); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); // Step-2: identify the stored procedure String simpleProc = "{ call simpleproc(?) }"; // Step-3: prepare the callable statement CallableStatement cs = conn.prepareCall(simpleProc); // Step-4: register output parameters ... cs.registerOutParameter(1, java.sql.Types.INTEGER); // Step-5: execute the stored procedures: proc3 cs.execute();// w ww. ja va2 s .c om // Step-6: extract the output parameters int param1 = cs.getInt(1); System.out.println("param1=" + param1); // Step-7: get ParameterMetaData ParameterMetaData pmeta = cs.getParameterMetaData(); if (pmeta == null) { System.out.println("Vendor does not support ParameterMetaData"); } else { System.out.println(pmeta.getParameterType(1)); } conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);// w ww. j a va2 s .c om String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); CallableStatement cs = connection.prepareCall("{call myprocinout(?)}"); // Register the type of the IN/OUT parameter cs.registerOutParameter(1, Types.VARCHAR); // Set the value for the IN/OUT parameter cs.setString(1, "a string"); // Execute the stored procedure and retrieve the IN/OUT value cs.execute(); String outParam = cs.getString(1); // OUT parameter System.out.println(outParam); }