@Test public void testRestoreDivers() throws Exception { DriverManager.registerDriver(new TestDriver()); DriverManager.registerDriver(new TestDriver()); ArrayList oldDrivers = new ArrayList(); Enumeration drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { oldDrivers.add(drivers.nextElement()); } JDBCMockObjectFactory factory = new JDBCMockObjectFactory(); new JDBCMockObjectFactory(); new JDBCMockObjectFactory(); drivers = DriverManager.getDrivers(); assertTrue(drivers.nextElement() instanceof MockDriver); assertFalse(drivers.hasMoreElements()); factory.restoreDrivers(); drivers = DriverManager.getDrivers(); int numberDrivers = 0; while (drivers.hasMoreElements()) { numberDrivers++; assertTrue(oldDrivers.contains(drivers.nextElement())); } factory.restoreDrivers(); factory.restoreDrivers(); factory.restoreDrivers(); int newNumberDrivers = 0; drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { newNumberDrivers++; assertTrue(oldDrivers.contains(drivers.nextElement())); } assertTrue(numberDrivers == newNumberDrivers); factory.registerMockDriver(); drivers = DriverManager.getDrivers(); numberDrivers = 0; while (drivers.hasMoreElements()) { numberDrivers++; assertTrue(drivers.nextElement() instanceof MockDriver); } assertTrue(numberDrivers == 1); factory.registerMockDriver(); factory.registerMockDriver(); factory.restoreDrivers(); factory.restoreDrivers(); drivers = DriverManager.getDrivers(); numberDrivers = 0; while (drivers.hasMoreElements()) { numberDrivers++; assertTrue(oldDrivers.contains(drivers.nextElement())); } assertTrue(numberDrivers == newNumberDrivers); }
@Test public void testOneDriver() throws Exception { DriverManager.registerDriver(new TestDriver()); DriverManager.registerDriver(new TestDriver()); getJDBCMockObjectFactory(); Enumeration drivers = DriverManager.getDrivers(); assertTrue(drivers.nextElement() instanceof MockDriver); assertFalse(drivers.hasMoreElements()); super.tearDown(); drivers = DriverManager.getDrivers(); assertTrue(drivers.hasMoreElements()); drivers.nextElement(); assertTrue(drivers.hasMoreElements()); }
public Connection connect() throws TechnicalException { Connection connection = null; String connectionString = null; try { if (databaseParameter.getRdbs().isMySql()) { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); connectionString = "jdbc:mysql://" + databaseParameter.getDatabaseHost() + ":" + databaseParameter.getDatabasePort() + "/" + databaseParameter.getDatabaseName(); } else if (databaseParameter.getRdbs().isPostgreSql()) { DriverManager.registerDriver(new org.postgresql.Driver()); connectionString = "jdbc:postgresql://" + databaseParameter.getDatabaseHost() + ":" + databaseParameter.getDatabasePort() + "/" + databaseParameter.getDatabaseName(); } else if (databaseParameter.getRdbs().isOracle()) { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); connectionString = "jdbc:oracle:thin:@" + databaseParameter.getDatabaseHost() + ":" + databaseParameter.getDatabasePort() + ":" + databaseParameter.getDatabaseName(); } connection = DriverManager.getConnection( connectionString, databaseParameter.getDatabaseUser(), databaseParameter.getDatabasePassword()); if (databaseParameter.getRdbs().isPostgreSql()) { connection.setAutoCommit( false); // Need to explicitely set auto-commit to false (for streaming results) } } catch (SQLException e) { throw new TechnicalException(connectionString, e); } return connection; }
public void actionPerformed(ActionEvent e) { try { String name = JOptionPane.showInputDialog("Enter the UserId:"); String name1 = JOptionPane.showInputDialog("Enter the Password:"******"Enter the MobileNo:"); // int name2=Integer.parseInt(name22); String name3 = JOptionPane.showInputDialog("Enter the DOB(dd/mm/yyyy):"); DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe", "system", "9696030257"); Statement st = con.createStatement(); st.executeUpdate( "insert into database values('" + name + "','" + name1 + "','" + name2 + "','" + name3 + "')"); st.executeUpdate("commit"); JOptionPane.showMessageDialog( null, "Hi !! Welcome in Our Database.Your userId is < " + name + " > And Password is < ******* >"); } catch (Exception ex) { System.out.print(ex); JOptionPane.showMessageDialog(null, "Please Fill All Entry OR choose another UsetId."); } }
/** * Loads the specified class using the supplied class loader and registers the driver with the * driver manager. * * @param className the fully qualified name of the desired class * @param loader the class loader to use when loading the driver * @return the loaded Driver * @throws DriverLoadException thrown if the driver cannot be loaded */ private static Driver load(String className, ClassLoader loader) throws DriverLoadException { try { final Class c = Class.forName(className, true, loader); // final Class c = loader.loadClass(className); final Driver driver = (Driver) c.newInstance(); final Driver shim = new DriverShim(driver); // using the DriverShim to get around the fact that the DriverManager won't register a driver // not in the base class path DriverManager.registerDriver(shim); return shim; } catch (ClassNotFoundException ex) { final String msg = String.format("Unable to load database driver '%s'", className); LOGGER.debug(msg, ex); throw new DriverLoadException(msg, ex); } catch (InstantiationException ex) { final String msg = String.format("Unable to load database driver '%s'", className); LOGGER.debug(msg, ex); throw new DriverLoadException(msg, ex); } catch (IllegalAccessException ex) { final String msg = String.format("Unable to load database driver '%s'", className); LOGGER.debug(msg, ex); throw new DriverLoadException(msg, ex); } catch (SQLException ex) { final String msg = String.format("Unable to load database driver '%s'", className); LOGGER.debug(msg, ex); throw new DriverLoadException(msg, ex); } }
static Connection connectToDb(String uname, String pword) throws SQLException { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection con = DriverManager.getConnection( "jdbc:oracle:thin:hr/[email protected]:1521:orcl", uname.trim(), pword.trim()); return con; }
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException { Object obj = JSONValue.parse(req.getReader()); JSONArray array = (JSONArray) obj; JSONObject requestParams = (JSONObject) array.get(0); int radioID = requestParams.get("radio") == null ? 0 : Integer.parseInt((String) requestParams.get("radio")); long userID = requestParams.get("userId") == null ? 0 : (long) requestParams.get("userId"); @SuppressWarnings("unchecked") ArrayList<String> checkboxList = (ArrayList<String>) requestParams.get("checkboxes"); String query = queryBuilder(radioID, userID, checkboxList); PrintWriter out = res.getWriter(); res.setContentType("text/html; charset=UTF-8"); String endJson = ""; if (query != null) { try { java.sql.DriverManager.registerDriver(new com.google.appengine.api.rdbms.AppEngineDriver()); c = java.sql.DriverManager.getConnection("jdbc:google:rdbms://valiminee:evalimine2/db"); if (c != null) { java.sql.ResultSet rs = c.createStatement().executeQuery(query); endJson = ResultSetConverter.convert(rs).toString(); } } catch (java.sql.SQLException | JSONException e) { e.printStackTrace(); } } out.print(endJson); }
protected static synchronized PhoenixTestDriver initDriver(ReadOnlyProps props) throws Exception { if (driver == null) { driver = new PhoenixTestDriver(props); DriverManager.registerDriver(driver); } return driver; }
static { try { DriverManager.registerDriver(new SqlAwareHsqldbDriver()); } catch (SQLException ex) { UncheckedException.rethrow(ex); } }
/** * Verbindet dieses Object mit der Datenbank und gibt <code>true</code> zurück, wenn die * Verbindung erfolgreich aufgebaut wurde, sonst ein <code>false</code>. * * @return <code>true</code> wenn die Verbindung erfolgreich aufgebaut wurde, sonst <code>false * </code>. */ public boolean connect() { boolean isConnected = true; Driver embeddedDriver = new org.apache.derby.jdbc.EmbeddedDriver(); try { DriverManager.registerDriver(embeddedDriver); } catch (SQLException ex) { System.out.println(ex.getMessage()); } try { connection = DriverManager.getConnection(jdbcURL); } catch (SQLException ex) { isConnected = false; System.out.println("Connection could not be established."); } return isConnected; }
static { String title = ING_TRACE_NAME + "-Driver"; /* ** Initialize Ingres driver tracing. */ IngConfig.setDriverVers(driverMajorVersion, driverMinorVersion, driverPatchVersion); TraceLog traceLog = IngTrace.getTraceLog(); /* ** Create IngresDriver object and register with DriverManager. */ try { DriverManager.registerDriver(new IngresDriver()); DriverManager.println( ING_DRIVER_NAME + ": Version " + driverMajorVersion + "." + driverMinorVersion + "." + driverPatchVersion + " (" + driverJdbcVersion + ")"); DriverManager.println(driverVendor); traceLog.write(title + ": registered"); } catch (Exception ex) { DriverManager.println(ING_DRIVER_NAME + ": registration failed!"); traceLog.write(title + ": registration failed!"); } } // <class initializer>
public Connection connect(String url, Properties info) throws SQLException { if (acceptsURL(url)) { String fileName = getFileNameFromUrl(url); try { Configuration configuration = configLoader.load(fileName); List<String> drivers = configuration.getDrivers(); for (String classname : drivers) { Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(classname); Driver driver = driverClass.newInstance(); java.sql.DriverManager.registerDriver(driver); logger.debug("Registering driver " + classname); } List<ConnectionInfo> connections = configuration.getConnections(); ConnectionsHolder connectionsHolder = new ConnectionsHolder(); for (ConnectionInfo connectionInfo : connections) { Properties properties = new Properties(info); properties.setProperty("user", connectionInfo.getUser()); properties.setProperty("password", connectionInfo.getPassword()); Connection connection = DriverManager.getConnection(connectionInfo.getUrl(), properties); connectionsHolder.add(connectionInfo.getName(), connection); } return new ShardsConnection(connectionsHolder, configuration); } catch (Exception e) { throw new SQLException("Cannot load configuration file", e); } } else { return null; } }
static { try { java.sql.DriverManager.registerDriver(new Driver()); } catch (java.sql.SQLException E) { E.printStackTrace(); } }
/** * Constructs a new OracleDatabase from a user, a password and a host * * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws SQLException */ public OracleDatabase(String user, String password, String host, String port, String inst) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { this(); if (password == null) password = ""; if (host == null || host.length() == 0) host = "localhost"; if (port == null || port.length() == 0) port = "1521"; if (inst == null || inst.length() == 0) inst = "oracle"; connectionString = "jdbc:oracle:thin:" + user + "/" + password + "@" + host + ":" + port + ":" + inst; Driver driver; driver = (Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); DriverManager.registerDriver(driver); resetConnection(); description = "ORACLE database " + user + "/" + password + " at " + host + ":" + port + " instance " + inst; }
public Sql2oTest(Driver driverToRegister, String url, String user, String pass, String testName) { if (driverToRegister != null) { try { DriverManager.registerDriver(driverToRegister); } catch (SQLException e) { throw new RuntimeException( "could not register driver '" + driverToRegister.getClass().getName() + "'", e); } } this.sql2o = new Sql2o(url, user, pass); HashMap<String, String> defaultColumnMap = new HashMap<String, String>(); defaultColumnMap.put("ID", "id"); defaultColumnMap.put("NAME", "name"); defaultColumnMap.put("EMAIL", "email"); defaultColumnMap.put("TEXT", "text"); defaultColumnMap.put("ANUMBER", "aNumber"); defaultColumnMap.put("ALONGNUMBER", "aLongNumber"); sql2o.setDefaultColumnMappings(defaultColumnMap); this.url = url; this.user = user; this.pass = pass; if ("HyperSQL DB test".equals(testName)) { sql2o.createQuery("set database sql syntax MSS true").executeUpdate(); } }
private void btnDeleteActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnDeleteActionPerformed Connection dbConnection = null; PreparedStatement pstatement = null; String sql; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); dbConnection = DriverManager.getConnection( "jdbc:oracle:thin:@deltahiti31202:1521:XE", "Kaushal", "thullu"); sql = "DELETE FROM EMPLOYEES WHERE EMPLOYEE_ID=?"; pstatement = dbConnection.prepareStatement(sql); pstatement.setInt(1, Integer.parseInt(txtEmployeeID.getText())); pstatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (dbConnection != null && !dbConnection.isClosed()) { dbConnection.close(); } if (pstatement != null) { pstatement.close(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // GEN-LAST:event_btnDeleteActionPerformed
static { try { java.sql.DriverManager.registerDriver(new ShardsDriver()); } catch (SQLException e) { logger.error("Error when registering a driver", e); } }
private void btnInsertActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnInsertActionPerformed Connection dbConnection = null; PreparedStatement pstatement = null; String sql; try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); dbConnection = DriverManager.getConnection( "jdbc:oracle:thin:@deltahiti31202:1521:XE", "Kaushal", "thullu"); sql = "INSERT INTO EMPLOYEES(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,SALARY) VALUES (?,?,?,?)"; pstatement = dbConnection.prepareStatement(sql); pstatement.setInt(1, Integer.parseInt(txtEmployeeID.getText())); pstatement.setString(2, txtFirstName.getText()); pstatement.setString(3, txtLastName.getText()); pstatement.setDouble(4, Double.parseDouble(txtSalary.getText())); pstatement.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (dbConnection != null && !dbConnection.isClosed()) { dbConnection.close(); } if (pstatement != null) { pstatement.close(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // GEN-LAST:event_btnInsertActionPerformed
public static void main(String[] args) { Connection con = null; Statement stmt = null; try { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/java76db", "java76", "1111"); stmt = con.createStatement(); // update 실행 stmt.executeUpdate("update board set title='okok', content='okokxxx' where bno=9"); System.out.println("변경 성공!"); } catch (Exception e) { e.printStackTrace(); } finally { try { stmt.close(); } catch (Exception e) { } try { con.close(); } catch (Exception e) { } } }
/** * 创建一个数据库连接池,连接池中的可用连接的数量采用类成员 * * <p>initialConnections 中设置的值 */ public synchronized void createPool() throws Exception { // 确保连接池没有创建 // 如果连接池己经创建了,保存连接的向量 connections 不会为空 if (connections != null) { return; // 如果己经创建,则返回 } // 实例化 JDBC Driver 中指定的驱动类实例 Driver driver = (Driver) (Class.forName(this.jdbcDriver).newInstance()); DriverManager.registerDriver(driver); // 注册 JDBC 驱动程序 // 创建保存连接的向量 , 初始时有 0 个元素 connections = new Vector<PooledConnection>(); // 根据 initialConnections 中设置的值,创建连接。 createConnections(this.initialConnections); // System.out.println("create pool"); }
public static boolean registerDriver(Driver driver) { try { DriverManager.registerDriver(driver); try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName(MBEAN_NAME); if (!mbeanServer.isRegistered(objectName)) { mbeanServer.registerMBean(instance, objectName); } } catch (Throwable ex) { if (LOG == null) { LOG = LogFactory.getLog(DruidDriver.class); } LOG.warn("register druid-driver mbean error", ex); } return true; } catch (Exception e) { if (LOG == null) { LOG = LogFactory.getLog(DruidDriver.class); } LOG.error("registerDriver error", e); } return false; }
static { try { DriverManager.registerDriver(new DriverLoggingProxy()); } catch (Exception exception) { ConnectionLogger.error(exception.getMessage(), exception); } }
public static void installDriver(Driver driver) { try { DriverManager.registerDriver(driver); } catch (Exception e) { e.printStackTrace(); } }
public static void connect() { try { DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver()); link = DriverManager.getConnection(myURL); } catch (SQLException e) { System.out.println("Echec de la connexion : " + e.getMessage()); } }
public static void abrirConexao() throws SQLException { DriverManager.registerDriver(new FBDriver()); conexao = DriverManager.getConnection( "jdbc:firebirdsql:server1b/3050:D:/PROGRAM FILES/FIREBIRD/LTP4/BDVendas.GDB", "SYSDBA", "masterkey"); }
static { try { DriverManager.registerDriver(new MySQLTracingDriver()); } catch (SQLException e) { throw new RuntimeException( "register " + MySQLTracingDriver.class.getName() + " driver failure."); } }
static { try { DriverManager.registerDriver(INSTANCE = new PhoenixDriver()); } catch (SQLException e) { throw new IllegalStateException( "Untable to register " + PhoenixDriver.class.getName() + ": " + e.getMessage()); } }
/* * Load the Oracle JDBC driver */ private void loadDriver() { try { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); } catch (SQLException ex) { System.out.println("Message: " + ex.getMessage()); System.exit(-1); } }
public ConnectionFactory() { // Driver Manager- Manages our database driver // Singleton & ConnectionFactory try { DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); } catch (SQLException e) { e.printStackTrace(); } }
static { try { DriverManager.registerDriver(INSTANCE); } catch (SQLException e) { // Logging String logMsg = Messages.getString(Messages.JDBC.Err_registering, e.getMessage()); logger.log(Level.SEVERE, logMsg); } }