本文整理匯總了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());
}
示例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;
}
});
}
示例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;
}
示例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();
}
}
示例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;
}
});
}
示例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());
}
}
示例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);
}
示例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()));
}
}
示例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);
}
示例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));
}
示例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());
}
}
示例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;
}
示例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