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:JDBCVersionApp.java
public static void main(String args[]) throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@dssnt01:1521:dssora01", "scott", "tiger"); DatabaseMetaData meta = conn.getMetaData(); System.out.println("You're using version: " + meta.getDriverVersion() + " of the Oracle JDBC driver."); conn.close(); }
From source file:ExecuteExample.java
public static void main(String args[]) { try {//from w ww .ja v a2 s . c o 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[] argv) throws Exception { Connection con = null; PreparedStatement prepstmt;/*from w w w.j av a 2 s . c om*/ prepstmt = con.prepareStatement("UPDATE employee SET Name = ? " + " WHERE Id = ?"); prepstmt.setString(1, "Smith"); prepstmt.setString(2, "1"); prepstmt.executeUpdate(); prepstmt.close(); con.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);//from ww w.j a v a 2 s .c o m Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean isBatchingSupported = metadata.supportsBatchUpdates(); System.out.println("Batching Supported = " + isBatchingSupported); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName(DRIVER);// w w w . j a va 2 s.co m Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); DatabaseMetaData metadata = connection.getMetaData(); boolean isSupportTransaction = metadata.supportsTransactions(); System.out.println("Support Transaction = " + isSupportTransaction); connection.close(); }
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);/*w w w . ja v a 2s .co m*/ st.close(); conn.close(); }
From source file:DynaBeansExampleV3.java
public static void main(String args[]) throws Exception { Connection conn = getConnection(); PreparedStatement ps = conn// w w w. jav a 2 s. c o m .prepareStatement("SELECT * from movie, person " + "WHERE movie.director = person.Id"); ResultSet rs = ps.executeQuery(); RowSetDynaClass rsdc = new RowSetDynaClass(rs); conn.close(); Iterator itr = rsdc.getRows().iterator(); while (itr.hasNext()) { DynaBean bean = (DynaBean) itr.next(); System.err.println(bean.get("title")); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); System.out.println("JDBC Driver: " + md.getDriverName() + " " + md.getDriverVersion()); System.out.println("Database: " + md.getURL()); System.out.println("User: " + md.getUserName()); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/testdb", "root", ""); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = statement.executeQuery("SELECT * FROM products"); connection.close(); }
From source file:DataUpdater.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); DriverManager.registerDriver(new JdbcOdbcDriver()); String url = "jdbc:odbc:Contacts"; Connection con = DriverManager.getConnection(url); Statement stmt = con.createStatement(); String SQLCommand = "UPDATE CONTACT_INFO " + "SET STREET = '58 Broadway', ZIP = '10008' " + "WHERE First_Name = 'Michael' AND " + "Last_Name ='Corleone';"; stmt.execute(SQLCommand);/* w w w .j a v a 2 s . c o m*/ con.close(); }