當前位置: 首頁>>代碼示例>>Java>>正文


Java Driver類代碼示例

本文整理匯總了Java中com.mysql.jdbc.Driver的典型用法代碼示例。如果您正苦於以下問題:Java Driver類的具體用法?Java Driver怎麽用?Java Driver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Driver類屬於com.mysql.jdbc包,在下文中一共展示了Driver類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: accessors

import com.mysql.jdbc.Driver; //導入依賴的package包/類
@Test
public void accessors() {

    Map<String, Object> customProperties = new HashMap<String, Object>();
    customProperties.put(DbKeys.PORT_KEY, 123);

    DbConnMySQL dbConnection = new DbConnMySQL("host", "db", "user", "pass", customProperties);

    assertEquals(DbConnMySQL.DATABASE_TYPE, dbConnection.getDbType());
    assertEquals("host", dbConnection.getHost());
    assertEquals("db", dbConnection.getDb());
    assertEquals("user", dbConnection.getUser());
    assertEquals("pass", dbConnection.getPassword());
    assertEquals("jdbc:mysql://host:123/db", dbConnection.getURL());
    assertTrue(dbConnection.getConnHash().startsWith("host_123_db"));
    assertEquals("MySQL connection to host:123/db", dbConnection.getDescription());
    assertEquals(Driver.class, dbConnection.getDriverClass());
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:19,代碼來源:Test_DbConnMySQL.java

示例2: testDriverConnectNullArgument

import com.mysql.jdbc.Driver; //導入依賴的package包/類
/**
 * Test for Driver.connect() behavior clarifications:
 * - connect() throws SQLException if URL is null.
 */
public void testDriverConnectNullArgument() throws Exception {
    assertThrows(SQLException.class, "The url cannot be null", new Callable<Void>() {
        public Void call() throws Exception {
            Driver mysqlDriver = new Driver();
            mysqlDriver.connect(null, null);
            return null;
        }
    });

    assertThrows(SQLException.class, "The url cannot be null", new Callable<Void>() {
        public Void call() throws Exception {
            DriverManager.getConnection(null);
            return null;
        }
    });
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:21,代碼來源:ConnectionTest.java

示例3: dataSource

import com.mysql.jdbc.Driver; //導入依賴的package包/類
/**
 * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
 * directory called "jpaserver_derby_files".
 * 
 * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
 */
@Bean(destroyMethod = "close")
public DataSource dataSource() {
	BasicDataSource retVal = new BasicDataSource();
	/*
	retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
	retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
	retVal.setUsername("");
	retVal.setPassword("");
	* */
	 
	
	try
	{
		retVal.setDriver(new com.mysql.jdbc.Driver());
	}
	catch (Exception exc)
	{
		exc.printStackTrace();
	}
	retVal.setUrl("jdbc:mysql://localhost:3306/dhis2_fhir");
	retVal.setUsername("root");
	retVal.setPassword("");
	return retVal;
}
 
開發者ID:gerard-bisama,項目名稱:DHIS2-fhir-lab-app,代碼行數:31,代碼來源:FhirServerConfigDstu3.java

示例4: Database

import com.mysql.jdbc.Driver; //導入依賴的package包/類
public Database() {
    String url;
    
    try {
        DriverManager.registerDriver(new Driver());
        
        url = "jdbc:mysql://"
            + server + ":" + String.valueOf(port) + "/"
            + database
            + "?user=" + user
            + "&password=" + password;
        
        con = DriverManager.getConnection(url);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:klarkc,項目名稱:livraria,代碼行數:18,代碼來源:Database.java

示例5: testDriverAcceptsURLNullArgument

import com.mysql.jdbc.Driver; //導入依賴的package包/類
/**
 * Test for Driver.acceptsURL() behavior clarification:
 * - acceptsURL() throws SQLException if URL is null.
 */
public void testDriverAcceptsURLNullArgument() {
    assertThrows(SQLException.class, "The url cannot be null", new Callable<Void>() {
        public Void call() throws Exception {
            Driver mysqlDriver = new Driver();
            mysqlDriver.acceptsURL(null);
            return null;
        }
    });
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:14,代碼來源:ConnectionTest.java

示例6: BaseBugReport

import com.mysql.jdbc.Driver; //導入依賴的package包/類
/**
 * Constructor for this BugReport, sets up JDBC driver used to create
 * connections.
 */
public BaseBugReport() {
    try {
        this.driver = new Driver();
    } catch (SQLException ex) {
        throw new RuntimeException(ex.toString());
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:12,代碼來源:BaseBugReport.java

示例7: DataTransfer

import com.mysql.jdbc.Driver; //導入依賴的package包/類
public DataTransfer() throws SQLException, ClassNotFoundException {
	@SuppressWarnings("unused")
	Driver driver = new Driver();
	
	this.connection = DriverManager.getConnection("jdbc:mysql://localhost/osrs", "root", "");
	
	this.transfer(DataTable.ITEM);
}
 
開發者ID:Jarinus,項目名稱:osrs-private-server,代碼行數:9,代碼來源:DataTransfer.java

示例8: MySqlClient

import com.mysql.jdbc.Driver; //導入依賴的package包/類
@Inject
public MySqlClient(JdbcConnectorId connectorId, BaseJdbcConfig config, MySqlConfig mySqlConfig)
        throws SQLException
{
    super(connectorId, config, "`", new Driver());
    connectionProperties.setProperty("nullCatalogMeansCurrent", "false");
    if (mySqlConfig.isAutoReconnect()) {
        connectionProperties.setProperty("autoReconnect", String.valueOf(mySqlConfig.isAutoReconnect()));
        connectionProperties.setProperty("maxReconnects", String.valueOf(mySqlConfig.getMaxReconnects()));
    }
    if (mySqlConfig.getConnectionTimeout() != null) {
        connectionProperties.setProperty("connectTimeout", String.valueOf(mySqlConfig.getConnectionTimeout().toMillis()));
    }
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:15,代碼來源:MySqlClient.java

示例9: getConnect

import com.mysql.jdbc.Driver; //導入依賴的package包/類
public final static Connection getConnect() throws IOException, SQLException, ClassNotFoundException {
    Properties mysqlConf = PropertiesUtils.read(Project.getMySQLConfiguration());
    String dbserver = mysqlConf.getProperty("dbserver");
    String database = mysqlConf.getProperty("database");
    String username = mysqlConf.getProperty("username");
    String password = mysqlConf.getProperty("password");
    String connectUrl = String.format(CONNECT_URL_FORMAT, dbserver, database);
    Class.forName(Driver.class.getName());
    return DriverManager.getConnection(connectUrl, username, password);
}
 
開發者ID:MurphyL,項目名稱:StepInX,代碼行數:11,代碼來源:MySQLUtils.java

示例10: checkBug32216

import com.mysql.jdbc.Driver; //導入依賴的package包/類
private void checkBug32216(String host, String port, String dbname)
		throws SQLException {
	NonRegisteringDriver driver = new NonRegisteringDriver();

	StringBuffer url = new StringBuffer("jdbc:mysql://");
	url.append(host);

	if (port != null) {
		url.append(':');
		url.append(port);
	}

	url.append('/');
	url.append(dbname);

	Properties result = driver.parseURL(url.toString(), new Properties());

	assertEquals("hostname not equal", host,
			result.getProperty(Driver.HOST_PROPERTY_KEY));
	if (port != null) {
		assertEquals("port not equal", port,
				result.getProperty(Driver.PORT_PROPERTY_KEY));
	} else {
		assertEquals("port default incorrect", "3306",
				result.getProperty(Driver.PORT_PROPERTY_KEY));
	}

	assertEquals("dbname not equal", dbname,
			result.getProperty(Driver.DBNAME_PROPERTY_KEY));
}
 
開發者ID:hinsenchan,項目名稱:fil_project_mgmt_app_v2,代碼行數:31,代碼來源:ConnectionRegressionTest.java

示例11: BaseBugReport

import com.mysql.jdbc.Driver; //導入依賴的package包/類
/**
 * Constructor for this BugReport, sets up JDBC driver used to create
 * connections.
 */
public BaseBugReport() {
	try {
		this.driver = new Driver();
	} catch (SQLException ex) {
		throw new RuntimeException(ex.toString());
	}
}
 
開發者ID:hinsenchan,項目名稱:fil_project_mgmt_app_v2,代碼行數:12,代碼來源:BaseBugReport.java

示例12: connect

import com.mysql.jdbc.Driver; //導入依賴的package包/類
public Connection connect(){
		String userName = "honaro";
        String password = "honaro1234";
        String url = "jdbc:mysql://localhost/honaro?useUnicode=true&characterEncoding=UTF-8&jdbcCompliantTruncation=false";
       
        try{
        	Driver driver = (Driver) Class.forName ("com.mysql.jdbc.Driver").newInstance ();
//        	connection = driver.connect(string, Prop)
        	connection = DriverManager.getConnection (url, userName, password);
        } catch (Exception e){
        	e.printStackTrace();
        }
        
        return connection;
	}
 
開發者ID:wandrusz,項目名稱:wwwa,代碼行數:16,代碼來源:JDBCTest.java

示例13: haibaDataSource

import com.mysql.jdbc.Driver; //導入依賴的package包/類
@Bean
@Qualifier("haibaDataSource")
public DataSource haibaDataSource() throws Exception{
	String jdbcUrlPrefix = "jdbc:mysql://127.0.0.1:" + mysqlPort + "/";

	return new SimpleDriverDataSource(new Driver(), jdbcUrlPrefix + testHAIBADbName + "?createDatabaseIfNotExist=true", testHAIBADbUsername, testHAIBADbPassword);
}
 
開發者ID:trifork,項目名稱:HAIBA-EPIMIBA-classification,代碼行數:8,代碼來源:EPIMIBAIntegrationTestConfiguration.java


注:本文中的com.mysql.jdbc.Driver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。