List of usage examples for java.sql DriverManager getConnection
private static Connection getConnection(String url, java.util.Properties info, Class<?> caller) throws SQLException
From source file:TestDatabaseMetaDataToolDatabaseInformation.java
public static Connection getMySqlConnection() throws Exception { String driver = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost/databaseName"; String username = "root"; String password = "root"; Class.forName(driver);/*from www . j ava2s .c om*/ Connection conn = DriverManager.getConnection(url, username, password); return conn; }
From source file:ch.newscron.referral.ReferralManager.java
/** * Provides a connection to the database specified (see fields) * @return a Connection for the database *///from ww w .java2s.co m public static Connection connect() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection = DriverManager.getConnection(DBurl, username, password); return connection; } catch (SQLException e) { throw new IllegalStateException("Cannot connect the database! ", e); } catch (Exception ex) { Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:datatableinputdata.DataTableInputData.java
/** * @param args the command line arguments *//* w w w . ja va2s .com*/ private static void DBConnect() throws SQLException { CallableStatement cstmt = null; String serverIP = "192.168.16.13"; String portNumber = "1521"; String instanceName = "pudp"; String username = "argen666"; String password = "argen666"; DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); String url = "jdbc:oracle:thin:@" + serverIP + ":" + portNumber + ":" + instanceName; connection = DriverManager.getConnection(url, username, password); }
From source file:com.wavemaker.runtime.data.util.JDBCUtils.java
public static Connection getConnection(String url, String username, String password, String driverClassName) { try {// w ww.ja v a 2s. co m loadDriver(driverClassName); return DriverManager.getConnection(url, username, password); } catch (SQLException ex) { throw new DataServiceRuntimeException(ex); } }
From source file:com.att.pirates.util.DBUtility.java
public static Connection getDBConnection() throws SQLException, Exception { Connection conn = null;/* w ww . jav a 2 s. c om*/ PropertyReader reader = new PropertyReader(); String forName = reader.readPropertyByName(PiratesConstants.CLASSFORNAME); if (StringUtils.isBlank(forName) || StringUtils.isEmpty(forName)) { throw new Exception("forName is empty from property file"); } String serverName = reader.readPropertyByName(PiratesConstants.SERVERNAME); String databaseName = reader.readPropertyByName(PiratesConstants.DATABASENAME); String user = reader.readPropertyByName(PiratesConstants.USER); String password = reader.readPropertyByName(PiratesConstants.PASSWORD); if (StringUtils.isBlank(serverName) || StringUtils.isEmpty(databaseName) || StringUtils.isBlank(user) || StringUtils.isEmpty(password)) { throw new Exception("connection string is empty from property file"); } String url = serverName + ";" + "databaseName=" + databaseName; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager.getConnection(url, user, password); return conn; }
From source file:common.DB.java
public static Connection getConnection() { try {/*w ww.j a v a 2 s.c o m*/ if (connection == null) { Properties prop = new Properties(); InputStream inputStream = DB.class.getClassLoader().getResourceAsStream("/db.properties"); System.out.println(inputStream); prop.load(inputStream); String driver = prop.getProperty("driver"); String url = prop.getProperty("url"); String user = prop.getProperty("user"); String password = prop.getProperty("password"); Class.forName(driver); connection = DriverManager.getConnection(url, user, password); connection.setAutoCommit(true); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return connection; }
From source file:ch.newscron.registration.UserRegistration.java
/** * Provides a connection to the database specified (see fields) * @return a Connection for the database *///from ww w . j a v a 2 s . co m public static Connection connect() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection = DriverManager.getConnection(DBurl, username, password); return connection; } catch (SQLException e) { throw new IllegalStateException("Cannot connect the database! ", e); } catch (Exception ex) { Logger.getLogger(UserRegistration.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:Main.java
private static Connection getHSQLConnection() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); String url = "jdbc:hsqldb:mem:data/tutorial"; DriverManager.setLoginTimeout(60); // fail after 60 seconds return DriverManager.getConnection(url, "sa", ""); }
From source file:com.products.products.java
private static Connection getConnection() { Connection conn = null;//from w w w . java 2 s . co m try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException ex) { System.err.println("JDBC Driver Not Found: " + ex.getMessage()); } try { String jdbc = "jdbc:mysql://ipro.lambton.on.ca/inventory"; conn = DriverManager.getConnection(jdbc, "products", "products"); } catch (SQLException ex) { System.err.println("Failed to Connect: " + ex.getMessage()); } return conn; }
From source file:Main.java
public static Connection getMySqlConnection() throws Exception { String driver = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost/demo2s"; String username = "oost"; String password = "oost"; Class.forName(driver);/*from www . j a v a2 s . co m*/ Connection conn = DriverManager.getConnection(url, username, password); return conn; }