List of usage examples for java.sql DriverManager getConnection
@CallerSensitive public static Connection getConnection(String url) throws SQLException
From source file:Performance.java
public Performance() { try {/*from ww w. j a v a 2 s . c o m*/ Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception e) { System.err.println("unable to load driver"); } try { connection = DriverManager .getConnection("jdbc:mysql://192.168.1.81/archives?user=archives&password=archives"); } catch (SQLException e) { System.out.println("SQLException: " + e.getMessage()); System.out.println("SQLState: " + e.getSQLState()); System.out.println("VendorError: " + e.getErrorCode()); } }
From source file:HelloMySQLJDBC.java
public void connectToDB() { try {//w w w. j a v a 2 s. c om connection = DriverManager .getConnection("jdbc:mysql://192.168.1.25/accounts?user=spider&password=spider"); } catch (SQLException e) { displaySQLErrors(e); } }
From source file:com.reydentx.core.client.MySqlClientFactory.java
@Override public Connection create() throws Exception { Class.forName("com.mysql.jdbc.Driver"); return DriverManager.getConnection(url); }
From source file:Main.java
/** * <p>//from w w w .j av a 2 s . c o m * Get the connection to the local database. * </p> */ public static Connection getLocalConnection() throws SQLException { return DriverManager.getConnection("jdbc:default:connection"); }
From source file:fp4f.floorplans.DatabaseLayer.java
DatabaseLayer() { // load the sqlite-JDBC driver using the current class loader try {//from w w w .ja v a 2 s . co m Class.forName("org.sqlite.JDBC"); con = DriverManager.getConnection("jdbc:sqlite:floorplans.sqlite"); } catch (Exception ex) { System.out.println(ex); } }
From source file:com.megatome.j2d.support.DBSupport.java
/** * Create a new DB file, and insert all of the specified index values. * @param indexValues Index values to insert into the DB * @param dbFileDir Directory to create the DB file in. * @throws BuilderException//from w w w . j a v a2 s. com */ public static void createIndex(List<SearchIndexValue> indexValues, String dbFileDir) throws BuilderException { final String dbFile = concat(dbFileDir, DB_FILE); // Create DB file try (final Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile); final Statement stmt = connection.createStatement()) { stmt.execute(CREATE_INDEX_SQL); // Update DB try (final PreparedStatement pst = connection.prepareStatement(INSERT_INDEX_SQL)) { for (final SearchIndexValue value : indexValues) { pst.setString(1, value.getName()); pst.setString(2, value.getType().getTypeName()); pst.setString(3, value.getPath()); pst.execute(); } } } catch (SQLException e) { throw new BuilderException("Error writing to SQLite DB", e); } logVerbose("Created the SQLite search index"); }
From source file:io.muic.ooc.webapp.service.UserService.java
public Connection connectSQL() { // MySQL Connection try {/*from w w w. j a v a 2 s . co m*/ Class.forName(MY_DRIVER); // load driver Connection conn = DriverManager.getConnection("jdbc:mysql://" + DB_HOST + ":" + DB_PORT + "/" + DB_NAME + "?" + "user=" + MY_USERNAME + "&" + "password=" + MY_PASSWORD); s = conn.createStatement(); return conn; } catch (ClassNotFoundException e) { // System.out.println("Driver not found " + e); } catch (SQLException e) { System.out.println("Connection not possible" + e); } return null; }
From source file:com.libraryloan.DerbyBookDAO.java
@Override public void setup() throws Exception { connection = DriverManager.getConnection("jdbc:derby:books.db;create=true"); dbAccess.update(connection,/*from w w w . jav a2s. c o m*/ "CREATE TABLE Books (" + "uniqueID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)," + "name VARCHAR(30), authors VARCHAR(100), publishedYear INTEGER, available BOOLEAN" + ")"); }
From source file:oobbit.database.ConnectionManager.java
/** * Connects to the Database described in the database properties file. *///from w ww . ja v a 2 s . c o m @PostConstruct public void connect() { try { connection = DriverManager.getConnection(settings.getConnectorString()); } catch (SQLException ex) { connection = null; Logger.getLogger(ConnectionManager.class.getName()).log(Level.SEVERE, "Unexpected SQLException occured.", ex); System.exit(1); // Force quit (TODO?) } }
From source file:AppletJDBCDrop.java
public void init() { Connection connection;// w w w. j a v a 2 s . c om try { Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager .getConnection("jdbc:mysql://192.168.1.25/accounts?user=spider&password=spider"); } catch (Exception connectException) { connectException.printStackTrace(); } Container c = getContentPane(); tableList = new JList(); loadTables(); c.add(new JScrollPane(tableList), BorderLayout.NORTH); dropButton = new JButton("Drop Table"); dropButton.addActionListener(this); c.add(dropButton, BorderLayout.SOUTH); }