List of usage examples for java.sql Connection close
void close() throws SQLException;
Connection
object's database and JDBC resources immediately instead of waiting for them to be automatically released. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); DatabaseMetaData dbMd = conn.getMetaData(); if (dbMd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)) { System.out.println("Transaction Isolation level " + "TRANSACTION_READ_COMMITTED is supported."); conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); }/*from ww w. j av a 2s. c o m*/ conn.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)); }/*from w w w. j a va2 s . c o m*/ stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "jdbc:mysql://localhost:3306/"; String dbName = "jdbcMysql"; String userName = "root"; String password = "root"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection(url + dbName, userName, password); Statement st = conn.createStatement(); int rows = st.executeUpdate("INSERT INTO myTable SELECT * FROM jdbc4.Copyemployee"); if (rows == 0) { System.out.println("Don't add any row!"); } else {/* ww w . j a v a 2 s . com*/ System.out.println(rows + " row(s)affected."); conn.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from w ww. j av a 2s . c om*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); String[] functions = metadata.getTimeDateFunctions().split(",\\s*"); for (int i = 0; i < functions.length; i++) { String function = functions[i]; System.out.println("Function = " + function); } connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);//from ww w. j a v a 2s. c om Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); String[] functions = metadata.getStringFunctions().split(",\\s*"); for (int i = 0; i < functions.length; i++) { String function = functions[i]; System.out.println("Function = " + function); } connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String url = "jdbc:mysql://localhost:3306/"; String dbName = "jdbc4"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "root"; Class.forName(driver).newInstance(); Connection conn = DriverManager.getConnection(url + dbName, userName, password); Statement st = conn.createStatement(); int rows = st.executeUpdate("INSERT INTO Copyemployee SELECT * FROM employee"); if (rows == 0) { System.out.println("Don't add any row!"); } else {/*from w w w. j a va 2 s . c o m*/ System.out.println(rows + " row(s)affected."); conn.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, username, password); CallableStatement stmt = conn.prepareCall("{call CREATE_USERS (?, ?, ?, ?, ?, ?)}"); stmt.setString(1, "a"); stmt.setString(2, "b"); stmt.setString(3, "c"); stmt.setString(4, "d"); stmt.setString(5, "e"); stmt.setString(6, "f"); stmt.execute();/* ww w . jav a2 s.c om*/ conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ResultSet resultSet = null;//from w w w . j a v a 2 s. co m Class.forName(DRIVER); Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); resultSet = metadata.getTypeInfo(); while (resultSet.next()) { String typeName = resultSet.getString("TYPE_NAME"); System.out.println("Type Name = " + typeName); } resultSet.close(); connection.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driver = "com.mysql.jdbc.Driver"; String user = "root"; String pass = "root"; Class.forName(driver).newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", user, pass); Statement st = con.createStatement(); ResultSet res = st.executeQuery("SELECT * FROM emp"); while (res.next()) { int i = res.getInt("ID"); String s = res.getString("name"); System.out.println(i + "\t\t" + s); }/*from w w w . j a v a 2s . c o m*/ con.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);/*from ww w. j a v a2 s . co m*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); String[] functions = metadata.getNumericFunctions().split(",\\s*"); for (int i = 0; i < functions.length; i++) { String function = functions[i]; System.out.println("Function = " + function); } connection.close(); }