List of usage examples for java.sql Statement close
void close() throws SQLException;
Statement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = null;//w w w. j a v a2 s .c om Statement stmt = null; Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};" + "DBQ=C:\\Users\\Public\\uls\\ulsTest.mdb;" + "SystemDB=C:\\Users\\Public\\uls\\Security.mdw;" + "Uid=Gord;" + "Pwd=obfuscated;" + "ExtendedAnsiSQL=1;"); String UID = "Tim"; String oldPWD = "oldpassword"; String newPWD = "I like Java"; Statement s = conn.createStatement(); s.execute("ALTER USER " + UID + " PASSWORD \"" + newPWD + "\" \"" + oldPWD + "\""); s.close(); conn.close();/*from ww w.j a va 2s .com*/ }
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);"); getTables(conn);//from w ww . j av a 2s . c om st.close(); conn.close(); }
From source file:ExecuteExample.java
public static void main(String args[]) { try {//from w w w . j av a 2 s .co m Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (Exception e) { System.out.println("JDBC-ODBC driver failed to load."); return; } try { Connection con = DriverManager.getConnection("jdbc:odbc:Inventory", "", ""); Statement stmt = con.createStatement(); stmt.execute("CREATE TABLE SalesHistory(ProductID NUMBER,Price CURRENCY, TrnsDate DATE)"); stmt.close(); con.close(); } catch (Exception e) { System.out.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String url = "jdbc:odbc:databaseName"; String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user = "guest"; String password = "guest"; String theStatement = "SELECT lastname, firstname FROM autors"; try {//from w ww .j a v a2 s . c o m Class.forName(driver); Connection connection = DriverManager.getConnection(url, user, password); Statement queryAuthors = connection.createStatement(); ResultSet theResults = queryAuthors.executeQuery(theStatement); queryAuthors.close(); } catch (ClassNotFoundException cnfe) { System.err.println(cnfe); } catch (SQLException sqle) { String sqlMessage = sqle.getMessage(); String sqlState = sqle.getSQLState(); int vendorCode = sqle.getErrorCode(); System.err.println("Exception occurred:"); System.err.println("Message: " + sqlMessage); System.err.println("SQL state: " + sqlState); System.err.println("Vendor code: " + vendorCode + "\n----------------"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//server.local:1521/prod", "scott", "tiger"); conn.setAutoCommit(false);/*from www . j a v a 2 s . c o m*/ Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select * from employee"); while (rset.next()) { System.out.println(rset.getString(1)); } stmt.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { System.setProperty("oracle.net.tns_admin", "C:/app/product/11.2.0/client_1/NETWORK/ADMIN"); String dbURL = "jdbc:oracle:thin:@ENTRY_FROM_TNSNAMES"; Class.forName("oracle.jdbc.OracleDriver"); Connection conn = DriverManager.getConnection(dbURL, "your_user_name", "your_password"); System.out.println("Connection established"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT dummy FROM dual"); if (rs.next()) { System.out.println(rs.getString(1)); }// w ww. j av a 2 s . co m stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn = null;//w w w . j av a2 s . c o m Properties info = new Properties(); // info.put("proxy_type", "4"); // SSL Tunneling info.put("proxy_host", "[proxy host]"); info.put("proxy_port", "[proxy port]"); info.put("proxy_user", "[proxy user]"); info.put("proxy_password", "[proxy password]"); info.put("user", "[db user]"); info.put("password", "[db pass word]"); conn = DriverManager.getConnection("jdbc:mysql://[db host]/", info); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("Select NOW()"); rs.next(); System.out.println("Data- " + rs.getString(1)); rs.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@localhost:1521:XE"; String userName = "suru"; String password = "password"; Connection con = DriverManager.getConnection(url, userName, password); System.out.println("Connection success!"); Statement stmt = con.createStatement(); String sql = "CREATE TABLE EMP ( ID NUMBER(5) PRIMARY KEY, NAME VARCHAR2(50))"; stmt.execute(sql);//from w w w .j ava 2 s . c o m System.out.println("Table created successfully!"); stmt.close(); con.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};" + "Dbq=C:\\Users\\Public\\uls\\ulsTest.mdb;" + "SystemDB=C:\\Users\\Public\\uls\\Security.mdw;" + "Uid=Gord;" + "Pwd=obfuscated;" + "ExtendedAnsiSQL=1;"); Statement s = conn.createStatement(); s.execute("CREATE USER Tim pwd"); System.out.println("User 'Tim' created."); s.execute("DROP USER Tim"); System.out.println("User 'Tim' dropped."); s.close(); conn.close();/*from ww w.ja v a 2 s . co m*/ }