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 { Class.forName(DRIVER);/*from w w w. j a v a 2 s.c om*/ Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); connection.close(); }
From source file:ConnectionExample.java
public static void main(String args[]) { try {// w w w . ja va 2 s . c om 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", "", ""); con.close(); } catch (Exception e) { System.out.println(e); } }
From source file:BasicDataSourceExample.java
public static void main(String args[]) throws Exception { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("com.mysql.jdbc.Driver"); bds.setUrl("jdbc:mysql://localhost/commons"); bds.setUsername("root"); bds.setPassword(""); // bds.setInitialSize(5); Connection connection = bds.getConnection(); System.err.println(connection); connection.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = null; conn = getConnection("jdbc:mysql://localhost/empDB", "root", "rootpass"); conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String driver = "com.mysql.jdbc.Driver"; String connection = "jdbc:mysql://localhost:3306/YourDBName"; String user = "root"; String password = "root"; Class.forName(driver);/* ww w . j a v a2s . c o m*/ Connection con = DriverManager.getConnection(connection, user, password); if (!con.isClosed()) { con.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String url = "jdbc:mysql://localhost:3306/mydb"; Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, "root", " "); System.out.println("Database connection established"); conn.close(); System.out.println("Database connection terminated"); }
From source file:DataInserter.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); DriverManager.registerDriver(new JdbcOdbcDriver()); String SQLCommand = "INSERT INTO CONTACT_INFO " + "(First_Name,MI,Last_Name,Street,City,State,Zip) " + "VALUES " + "('Michael','J','Corleone','86 Horsehead Blvd','NY','NY','12345');"; String url = "jdbc:odbc:Contacts"; Connection con = DriverManager.getConnection(url); Statement stmt = con.createStatement(); stmt.execute(SQLCommand);/*from w w w.j a v a 2 s . co m*/ con.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); System.out.println(md.getMaxStatements()); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); System.out.println(md.getSchemaTerm()); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); DatabaseMetaData md = conn.getMetaData(); System.out.println(md.getMaxConnections()); conn.close(); }