Example usage for java.sql Statement close

List of usage examples for java.sql Statement close

Introduction

In this page you can find the example usage for java.sql Statement close.

Prototype

void close() throws SQLException;

Source Link

Document

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Usage

From source file:TestSSL.java

public static void main(String[] argv) throws Exception {

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Properties prop = new Properties();
    prop.setProperty("user", "scott");
    prop.setProperty("password", "tiger");
    // THIS DOES NOT WORK YET
    prop.setProperty("oracle.net.ssl_cipher_suites",
            "(ssl_rsa_export_with_rc4_40_md5, ssl_rsa_export_with_des40_cbc_sha)");
    prop.setProperty("oracle.net.ssl_client_authentication", "false");
    prop.setProperty("oracle.net.ssl_version", "3.0");
    prop.setProperty("oracle.net.encryption_client", "REJECTED");
    prop.setProperty("oracle.net.crypto_checksum_client", "REJECTED");
    Connection conn = DriverManager.getConnection(
            "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCPS)(HOST = dssw2k01)(PORT = 2484))) (CONNECT_DATA = (SERVICE_NAME = DSSW2K01)))",
            prop);// w  w w  . j a  v a 2 s. c o m
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt
            .executeQuery("select 'Hello Thin driver SSL " + "tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:TestDataEncryptionIntegrity.java

public static void main(String[] argv) throws Exception {

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Properties prop = new Properties();
    prop.setProperty("user", "scott");
    prop.setProperty("password", "tiger");
    prop.setProperty("oracle.net.encryption_client", "REQUIRED");
    prop.setProperty("oracle.net.encryption_types_client", "( RC4_40 )");
    prop.setProperty("oracle.net.crypto_checksum_client", "REQUIRED");
    prop.setProperty("oracle.net.crypto_checksum_types_client", "( MD5 )");

    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", prop);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver Encryption & Integrity " + "tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();// w  w w.  j  a  va  2s  . c  o  m
    stmt.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = null;//from  ww w  .j  a  v  a  2 s . co m
    Statement stmt = null;

    Class.forName(JDBC_DRIVER);
    conn = DriverManager.getConnection(DB_URL, USER, PASS);
    stmt = conn.createStatement();

    String sql = "CREATE DATABASE STUDENTS";
    stmt.executeUpdate(sql);
    System.out.println("Database created successfully...");

    stmt.close();
    conn.close();
}

From source file:TestDSLookUp.java

public static void main(String[] args) throws SQLException, NamingException {

    Context ctx = null;//from   w  ww .  java  2 s .  co m
    try {
        Properties prop = new Properties();
        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        ctx = new InitialContext(prop);
    } catch (NamingException ne) {
        System.err.println(ne.getMessage());
    }

    DataSource ds = (DataSource) ctx.lookup("joe");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual");
    if (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    conn.setAutoCommit(false);// w ww .jav  a 2s. c  o m
    Statement st = conn.createStatement();

    PreparedStatement pstmt = conn.prepareStatement("create table survey (id int, name VARCHAR(30) );");

    pstmt.executeUpdate();

    ResultSet rs = st.executeQuery("SELECT * FROM survey");
    outputResultSet(rs);

    rs.close();
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();

    conn.setAutoCommit(false);/*  w  ww.  j av  a  2  s . c  om*/
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");

    st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    rs.close();
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection connection = getConnection();
    // Do work with connection
    Statement statement = connection.createStatement();
    String selectEmployeesSQL = "SELECT * FROM employees";
    ResultSet resultSet = statement.executeQuery(selectEmployeesSQL);

    while (resultSet.next()) {
        printEmployee(resultSet);/*from  w  w  w  .j  av a2s  .  co  m*/
    }
    resultSet.close();
    statement.close();
    connection.close();
}

From source file:EmployeeShow.java

public static void main(String[] args) throws Exception {
    ImageIcon image;/*from w w w  . j  a va 2  s.co m*/

    Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/c:\\employee");

    Statement s = con.createStatement();
    ResultSet rs = s.executeQuery("select photo from employee where name = 'Duke'");
    if (rs.next()) {
        Blob photo = rs.getBlob(1);
        ObjectInputStream ois = null;
        ois = new ObjectInputStream(photo.getBinaryStream());
        image = (ImageIcon) ois.readObject();
    }
    s.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String db_file_name_prefix = "c:\\mydbdir\\mydb";

    Connection con = null;/*  w  ww  .  j a  v a2 s . c o m*/
    Class.forName("org.hsqldb.jdbcDriver");

    con = DriverManager.getConnection("jdbc:hsqldb:file:" + db_file_name_prefix, // filenames
            "sa", // username
            ""); // password

    Statement statement = con.createStatement();
    ResultSet rs = statement.executeQuery("SELECT * FROM \"User\"");
    while (rs.next()) {
        System.out.print("ID: " + rs.getString("ID"));
        System.out.print(" first name: " + rs.getString("firstname"));
        System.out.println(" last name: " + rs.getString("lastname"));
    }
    statement.close();
    con.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();

    conn.setAutoCommit(false);//from w ww .ja  va2 s  .c  o  m
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    outputResultSet(rs);

    rs.close();
    st.close();
    conn.close();
}