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:Main.java

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

    st.executeUpdate("create table survey (id int,myURL CHAR);");
    st.executeUpdate("create view surveyview as (select * from survey);");
    getTables(conn);/*from  w  w  w .  jav  a 2 s.co m*/

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

From source file:Main.java

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

    st.executeUpdate("create table survey (id int,myURL CHAR);");

    String str = conn.nativeSQL("insert into survey(id) values(02)");

    System.out.println(str);

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

From source file:TestThinApp.java

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

    Class.forName("oracle.jdbc.driver.OracleDriver");
    //  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select 'Hello Thin driver tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();/*from  w  ww  .j  av  a  2s.co  m*/
    stmt.close();
    conn.close();
}

From source file:TestThinNet8App.java

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

    Class.forName("oracle.jdbc.driver.OracleDriver");
    //  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION = "
            + "(ADDRESS_LIST = (ADDRESS = " + "(PROTOCOL = TCP)(HOST = dssw2k01)(PORT = 1521)))"
            + "(CONNECT_DATA = (SERVICE_NAME = dssw2k01)))", "scott", "tiger");

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select 'Hello Thin driver tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();//from  w  w  w.  j  av  a2  s. c  o  m
    stmt.close();
    conn.close();
}

From source file:TestOCIApp.java

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

    Class.forName("oracle.jdbc.driver.OracleDriver");
    // or you can use:
    //  DriverManager.registerDriver(
    //   new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@dssnt01", "scott", "tiger");

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select 'Hello OCI driver tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();/*from  w w  w .java 2  s.  c  o m*/
    stmt.close();
    conn.close();
}

From source file:TestOCINet8App.java

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

    Class.forName("oracle.jdbc.driver.OracleDriver");
    // or you can use:
    //  DriverManager.registerDriver(
    //   new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@(DESCRIPTION = "
            + "(ADDRESS_LIST = (ADDRESS = " + "(PROTOCOL = TCP)(HOST = dssw2k01)(PORT = 1521)))"
            + "(CONNECT_DATA = (SERVICE_NAME = dssw2k01)))", "scott", "tiger");

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select 'Hello OCI driver tester '||USER||'!' result from dual");
    while (rset.next())
        System.out.println(rset.getString(1));
    rset.close();/*from w w w  .j  a  v a 2s .c o m*/
    stmt.close();
    conn.close();
}

From source file:TableMaker.java

public static void main(String[] args) throws Exception {
    Class.forName(jdbcDriver);//from   www.  j a v  a2 s.co m
    url += dbName;
    Connection con = null;
    Statement stmt = null;
    con = DriverManager.getConnection(url);
    stmt = con.createStatement();
    stmt.execute(SQLCreate);
    con.close();
    if (con != null) {
        con.close();
    }
    if (stmt != null) {
        stmt.close();
    }

}

From source file:Main.java

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

    Class.forName(JDBC_DRIVER);
    conn = DriverManager.getConnection(DB_URL, USER, PASS);
    System.out.println("Deleting database...");
    stmt = conn.createStatement();

    String sql = "DROP DATABASE STUDENTS";
    stmt.executeUpdate(sql);

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

From source file:JndiDataSource.java

public static void main(String args[]) throws Exception {
    String sp = "com.sun.jndi.fscontext.RefFSContextFactory";
    String file = "file:/e:/JNDI";
    String dataSourceName = "jdbc/myDatabase";

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
    env.put(Context.PROVIDER_URL, file);
    ctx = new InitialContext(env);

    bindDataSource(ctx, dataSourceName);

    DataSource ds = null;//  w  w  w .j  a va 2s . c  o  m
    ds = (DataSource) ctx.lookup(dataSourceName);

    Connection conn = ds.getConnection();

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Name FROM Employees");

    while (rs.next())
        System.out.println(rs.getString("name"));

    ctx.close();
    rs.close();
    stmt.close();
    conn.close();

    ctx.close();
    conn.close();
}

From source file:TestThinDSApp.java

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

    // These settings are typically configured in JNDI
    // so they a implementation specific
    OracleDataSource ds = new OracleDataSource();
    ds.setDriverType("thin");
    ds.setServerName("dssw2k01");
    ds.setPortNumber(1521);//w  w  w . j  a  v a2  s  .c  om
    ds.setDatabaseName("orcl"); // sid
    ds.setUser("scott");
    ds.setPassword("tiger");

    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();
}