Connection: prepareCall(String sql) : Connection « java.sql « Java by API






Connection: prepareCall(String sql)

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

public class Main {
  public static void main(String[] args) throws Exception {

    CallableStatement cs = conn.prepareCall("{call StoreProcedureName}");
    ResultSet rs = cs.executeQuery();

    while (rs.next()) {
      System.out.println("Defunct user: " + rs.getString("user"));
    }
  }

  static Connection conn;

  static Statement st;

  public static void setup() {
    try {
      // Step 1: Load the JDBC driver.
      Class.forName("org.hsqldb.jdbcDriver");
      System.out.println("Driver Loaded.");
      // Step 2: Establish the connection to the database.
      String url = "jdbc:hsqldb:data/tutorial";

      conn = DriverManager.getConnection(url, "sa", "");
      System.out.println("Got Connection.");

      st = conn.createStatement();
    } catch (Exception e) {
      System.err.println("Got an exception! ");
      e.printStackTrace();
      System.exit(0);
    }
  }
}

           
         
    
  








Related examples in the same category

1.Connection.TRANSACTION_NONE
2.Connection.TRANSACTION_READ_COMMITTED
3.Connection.TRANSACTION_READ_UNCOMMITTED
4.Connection.TRANSACTION_REPEATABLE_READ
5.Connection.TRANSACTION_SERIALIZABLE
6.Connection: close()
7.Connection: commit()
8.Connection: createStatement()
9.Connection: createStatement(int resultSetType, int resultSetConcurrency)
10.Connection: getAutoCommit()
11.Connection: getCatalog()
12.Connection: getMetaData()
13.Connection: getTransactionIsolation()
14.Connection: getWarnings()
15.Connection: nativeSQL(String sql)
16.Connection: prepareStatement(String sql)
17.Connection: rollback()
18.Connection: rollback(Savepoint savepoint)
19.Connection: setAutoCommit(boolean autoCommit)
20.Connection: setSavepoint(String name)
21.Connection: setTransactionIsolation(int level)