当前位置: 首页>>代码示例>>Java>>正文


Java Driver类代码示例

本文整理汇总了Java中java.sql.Driver的典型用法代码示例。如果您正苦于以下问题:Java Driver类的具体用法?Java Driver怎么用?Java Driver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Driver类属于java.sql包,在下文中一共展示了Driver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConnection

import java.sql.Driver; //导入依赖的package包/类
public static Connection getConnection() {
    try {
        DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());

        String url = "jdbc:mysql://" +       //db type
                "localhost:" +               //host name
                "3306/" +                    //port
                "db_example?" +              //db name
                "useSSL=false&" +            //do not use ssl
                "user=tully&" +              //login
                "password=tully";            //password

        return DriverManager.getConnection(url);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_04,代码行数:18,代码来源:ConnectionHelper.java

示例2: loadDrivers

import java.sql.Driver; //导入依赖的package包/类
/**
 * 装载和注册所有JDBC 驱动程序
 *
 * @param props 属性
 */
private void loadDrivers(Vector driverBeans) {
	logger.debug("----------------------->");
	Iterator iterator = driverBeans.iterator();
	while (iterator.hasNext()) {
		DSConfigBean dsConfigBean = (DSConfigBean)iterator.next();
		try {
			if (dsConfigBean.getDriver() != null && !"".equals(dsConfigBean.getDriver())){
				Driver driver = (Driver) Class.forName(dsConfigBean.getDriver())
						.newInstance();
				DriverManager.registerDriver(driver);
				drivers.addElement(driver);
				logger.debug("成功注册JDBC 驱动程序" + dsConfigBean.getDriver());
			}
		} catch (Exception e) {
			logger.error("注册驱动程序出错,",e);
		}
	}
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:24,代码来源:DBConnectionManager.java

示例3: getDriverClass

import java.sql.Driver; //导入依赖的package包/类
@Override
public Class<? extends Driver> getDriverClass(DbEnvironment env) {
    if (env.getDbServer() != null) {
        try {
            if (isSqlAnywhereDriverAvailable()) {
                return (Class<? extends Driver>) Class.forName(SQLANYWHERE_DRIVER_CLASS_NAME);
            } else if (isIanywhereDriverAvailable()) {
                return (Class<? extends Driver>) Class.forName(IANYWHERE_DRIVER_CLASS_NAME);
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    return super.getDriverClass(env);
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:17,代码来源:IqDbPlatform.java

示例4: getConnection

import java.sql.Driver; //导入依赖的package包/类
public Connection getConnection()
        throws SQLException {
    Driver driver = getDriver();

    Properties props = new Properties();

    if (stringHasValue(userId)) {
        props.setProperty("user", userId); //$NON-NLS-1$
    }

    if (stringHasValue(password)) {
        props.setProperty("password", password); //$NON-NLS-1$
    }

    props.putAll(otherProperties);

    Connection conn = driver.connect(connectionURL, props);

    if (conn == null) {
        throw new SQLException(getString("RuntimeError.7")); //$NON-NLS-1$
    }

    return conn;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:25,代码来源:JDBCConnectionFactory.java

示例5: driverPropertyInfoWithoutValues

import java.sql.Driver; //导入依赖的package包/类
@Test
public void driverPropertyInfoWithoutValues() throws SQLException
{
	Driver driver = getDriver();
	DriverPropertyInfo[] properties = driver.getPropertyInfo("jdbc:cloudspanner://localhost", null);
	assertEquals(12, properties.length);
	for (DriverPropertyInfo property : properties)
	{
		if (property.name.equals("AllowExtendedMode") || property.name.equals("AsyncDdlOperations")
				|| property.name.equals("AutoBatchDdlOperations"))
			assertEquals("false", property.value);
		else if (property.name.equals("ReportDefaultSchemaAsNull"))
			assertEquals("true", property.value);
		else
			assertNull(property.value);
	}
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:18,代码来源:CloudSpannerDriverTest.java

示例6: isDriverClass

import java.sql.Driver; //导入依赖的package包/类
private boolean isDriverClass(URLClassLoader jarloader, String className) {
    Class<?> clazz;

    try {
        clazz = jarloader.loadClass(className);
    } catch ( Throwable t ) {
        LOGGER.log(Level.FINE, null, t);
        
        LOGGER.log(Level.INFO, 
             "Got an exception trying to load class " +
             className + " during search for JDBC drivers in " +
             " driver jar(s): " + t.getClass().getName() + ": "
             + t.getMessage() + ".  Skipping this class..."); // NOI18N

        return false;         
    }

    if ( Driver.class.isAssignableFrom(clazz) ) {
        return true;
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:AddDriverDialog.java

示例7: getConnection

import java.sql.Driver; //导入依赖的package包/类
public Connection getConnection(ISqlConfig config) {
	if(conn == null){
		IConnectionParam param = config.getConnectionParam();
		 try {
			Driver d = (Driver)Class.forName
			 ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
			if(param.getUsername().trim().length()>0){
				// USERNAME & PASSWORD is configured, let's use it for connection
				conn = DriverManager.getConnection("jdbc:odbc:"+param.getURL(),param.getUsername(),param.getPassword());	
			} else {
				conn = DriverManager.getConnection("jdbc:odbc:"+param.getURL());	
			}
	
		 } catch (Exception e) {
			throw new RuntimeException(e);
		 }
	}
	return conn;
}
 
开发者ID:manikmagar,项目名称:adobe-air-db-connector,代码行数:20,代码来源:DnsConnectionManager.java

示例8: getDriver

import java.sql.Driver; //导入依赖的package包/类
/**
 * Get the driver for a JDBCDriver.  It only tries to load it using Class.forName() -
 * there is no URL to work with
 */
public Driver getDriver(JDBCDriver jdbcDriver) throws SQLException {
    ClassLoader l = getClassLoader(jdbcDriver);
    Object driver;
    try {
        driver = Class.forName(jdbcDriver.getClassName(), true, l).newInstance();
    } catch (Exception e) {
        SQLException sqlex = createDriverNotFoundException();
        sqlex.initCause(e);
        throw sqlex;
    }
    if (driver instanceof Driver) {
        return (Driver) driver;
    } else {
        throw new SQLException(driver.getClass().getName()
                + " is not a driver");                              //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:DbDriverManager.java

示例9: createConnection

import java.sql.Driver; //导入依赖的package包/类
public static Connection createConnection(Properties p,File[] f) throws Exception{
    String driver_name=p.getProperty(DRIVER_CLASS_NAME);
    String url=p.getProperty(URL);
    String user=p.getProperty(USER);
    String passwd=p.getProperty(PASSWORD);
    ArrayList list=new java.util.ArrayList();
    for(int i=0;i<f.length;i++){
        list.add(f[i].toURI().toURL());
    }
    URL[] driverURLs=(URL[])list.toArray(new URL[0]);
    URLClassLoader l = new URLClassLoader(driverURLs);
    Class c = Class.forName(driver_name, true, l);
    Driver driver=(Driver)c.newInstance();
    Connection con=driver.connect(url,p);
    return con;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:DbUtil.java

示例10: createFromJdbcUrl

import java.sql.Driver; //导入依赖的package包/类
private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url,
        Credential credential, int numThreads, ImmutableList<String> initSqls, Properties extraConnectionProperties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClass.getName());
    dataSource.setUrl(url);
    dataSource.setUsername(credential.getUsername());
    dataSource.setPassword(credential.getPassword());

    // connection pool settings
    dataSource.setInitialSize(numThreads);
    dataSource.setMaxActive(numThreads);
    // keep the connections open if possible; only close them via the removeAbandonedTimeout feature
    dataSource.setMaxIdle(numThreads);
    dataSource.setMinIdle(0);
    dataSource.setRemoveAbandonedTimeout(300);

    dataSource.setConnectionInitSqls(initSqls.castToList());
    if (extraConnectionProperties != null) {
        for (String key : extraConnectionProperties.stringPropertyNames()) {
            dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key));
        }
    }

    return dataSource;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:26,代码来源:JdbcDataSourceFactory.java

示例11: getDriverLoaderByName

import java.sql.Driver; //导入依赖的package包/类
/**
 * 加载对应路径jar包里的对应驱动
 *
 * @param fname 对应路径  如: lib4/ojdbc14.jar
 * @param dname 驱动名  如: oracle.jdbc.driver.OracleDriver
 * @return 加载到的驱动    java.sql.Driver
 * @throws Exception
 * @author tangxr
 */
public static Driver getDriverLoaderByName(String fname, String dname) throws Exception {
    if (null == fname || "".equals(fname)) {
        LOG.error("对应的驱动路径不存在,请确认.");
        return null;
    }
    if (null == dname || "".equals(dname)) {
        LOG.error("对应的驱动类的名字不存在.");
        return null;
    }
    File file = new File(fname);
    if (!file.exists()) {
        LOG.error("对应的驱动jar不存在.");
        return null;
    }
    URLClassLoader loader = new URLClassLoader(new URL[]{file.toURI().toURL()});
    loader.clearAssertionStatus();

    return (Driver) loader.loadClass(dname).newInstance();

}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:30,代码来源:DriverLoader.java

示例12: deregisterJdbcDrivers

import java.sql.Driver; //导入依赖的package包/类
private void deregisterJdbcDrivers() {
  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  Enumeration<Driver> drivers = DriverManager.getDrivers();

  while (drivers.hasMoreElements()) {
    LOGGER.debug("Deregistering JDBC Drivers:");
    Driver driver = drivers.nextElement();
    if (driver.getClass().getClassLoader() == classLoader) {
      try {
        LOGGER.debug("  {} v{}.{}",
            driver.getClass().getName(),
            driver.getMajorVersion(),
            driver.getMinorVersion()
        );

        DriverManager.deregisterDriver(driver);
      } catch (SQLException e) {
        LOGGER.error("Failed to deregister JDBC driver: ", e);
      }
    }
  }
}
 
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:23,代码来源:SampleApplicationDestroyListener.java

示例13: getConnection

import java.sql.Driver; //导入依赖的package包/类
@Override
public Connection getConnection()
        throws SQLException {
    Driver driver = getDriver();

    Properties props = new Properties();

    if (stringHasValue(userId)) {
        props.setProperty("user", userId); //$NON-NLS-1$
    }

    if (stringHasValue(password)) {
        props.setProperty("password", password); //$NON-NLS-1$
    }

    props.putAll(otherProperties);

    Connection conn = driver.connect(connectionURL, props);

    if (conn == null) {
        throw new SQLException(getString("RuntimeError.7")); //$NON-NLS-1$
    }

    return conn;
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:26,代码来源:JDBCConnectionFactory.java

示例14: setDriverClassName

import java.sql.Driver; //导入依赖的package包/类
/**
 * Set JDBC Driver class name to use
 * @param driverClassName JDBC Driver class name
 */
@SuppressWarnings("unchecked")
public void setDriverClassName(String driverClassName) {
	ObjectUtils.argumentNotNull(driverClassName, "Driver class must be not null");
	try {
		Class<?> driverClass = Class.forName(driverClassName.trim(), true, getClass().getClassLoader());

		if (!Driver.class.isAssignableFrom(driverClass)) {
			throw new IllegalStateException("Class: " + driverClassName + " is not a valid JDBC Driver class");
		}

		setDriverClass((Class<? extends Driver>) driverClass);

	} catch (ClassNotFoundException e) {
		throw new IllegalStateException("Failed to load JDBC driver class: " + driverClassName, e);
	}
}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:21,代码来源:DefaultBasicDataSource.java

示例15: getConnection

import java.sql.Driver; //导入依赖的package包/类
public Connection getConnection(JDBCConnectionConfiguration config)
		throws SQLException {
	Driver driver = getDriver(config);

	Properties props = new Properties();

	if (StringUtility.stringHasValue(config.getUserId())) {
		props.setProperty("user", config.getUserId()); //$NON-NLS-1$
	}

	if (StringUtility.stringHasValue(config.getPassword())) {
		props.setProperty("password", config.getPassword()); //$NON-NLS-1$
	}

	props.putAll(config.getProperties());

	Connection conn = driver.connect(config.getConnectionURL(), props);

	if (conn == null) {
		throw new SQLException(Messages.getString("RuntimeError.7")); //$NON-NLS-1$
	}

	return conn;
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:25,代码来源:ConnectionFactory.java


注:本文中的java.sql.Driver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。