java datasource mysql_Java MysqlDataSource類代碼示例
本站寻求有缘人接手,详细了解请联系站长QQ1493399855
本文整理匯總了Java中com.mysql.cj.jdbc.MysqlDataSource類的典型用法代碼示例。如果您正苦於以下問題:Java MysqlDataSource類的具體用法?Java MysqlDataSource怎麽用?Java MysqlDataSource使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。
MysqlDataSource類屬於com.mysql.cj.jdbc包,在下文中一共展示了MysqlDataSource類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: SQLDatabase
點讚 3
import com.mysql.cj.jdbc.MysqlDataSource; //導入依賴的package包/類
public SQLDatabase() {
dataSource = new MysqlDataSource();
dataSource.setDatabaseName("mantarologs");
dataSource.setUser("root");
dataSource.setPassword(MantaroData.config().get().getSqlPassword());
dataSource.setServerName("localhost");
dataSource.setURL(dataSource.getURL() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true&useSSL=false");
}
開發者ID:Mantaro,項目名稱:MantaroRPG,代碼行數:9,
示例2: main
public static void main(String[] args) throws SQLException {
MysqlDataSource mysqlDataSource = new MysqlDataSource();
mysqlDataSource.setPassword("moco");
mysqlDataSource.setUser("moco");
mysqlDataSource.setURL("jdbc:mysql://localhost:3306/moco");
Database.initialize(new MocoConfig.Builder(DataSourceSelector.single(mysqlDataSource), DatabaseType.MYSQL).build());
List result = Users.select()
.where(
Users.ID_CO.in(1, 2),
Users.NAME_CO.in("orekyuu", "jails")
).result();
User user = result.get(1);
System.out.println(user.owner.get().get().name);
開發者ID:orekyuu,項目名稱:Moco,代碼行數:17,
示例3: initDataSource
/**
* https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
*/
private void initDataSource() {
MysqlDataSource ds = new MysqlDataSource();
// set standard params
ds.setServerName(CONFIG.getDb().getIp());
ds.setPort(CONFIG.getDb().getPort());
ds.setDatabaseName(CONFIG.getDb().getSchema());
ds.setUser(CONFIG.getDb().getUserName());
ds.setPassword(CONFIG.getDb().getPassword());
// set non-standard params
ds.getModifiableProperty(PropertyDefinitions.PNAME_cachePrepStmts).setValue(true);
ds.getModifiableProperty(PropertyDefinitions.PNAME_prepStmtCacheSize).setValue(250);
ds.getModifiableProperty(PropertyDefinitions.PNAME_prepStmtCacheSqlLimit).setValue(2048);
ds.getModifiableProperty(PropertyDefinitions.PNAME_characterEncoding).setValue("utf8");
ds.getModifiableProperty(PropertyDefinitions.PNAME_serverTimezone).setValue("UTC");
HikariConfig hc = new HikariConfig();
hc.setDataSource(ds);
dataSource = new HikariDataSource(hc);
開發者ID:RWTH-i5-IDSG,項目名稱:steve-plugsurfing,代碼行數:26,
示例4: setupMySQL
點讚 2
* Set's up a MySQL dataSource so that you can run {@link SQLController#runSqlTask(SQLTask)}
* @param user MySQL User
* @param password MySQL user password
* @param serverName Server name
* @param dbName Database name
public void setupMySQL(String user, String password, String serverName, String dbName){
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser(user);
dataSource.setPassword(password);
dataSource.setDatabaseName(dbName);
dataSource.setServerName(serverName);
dataSource.setPort(3306);
dataSource.setPortNumber(3306);
dataSource.setUrl(dataSource.getUrl() + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true&useSSL=false");
SQLController.setDataSource(dataSource);
開發者ID:WalshyDev,項目名稱:JBA,代碼行數:20,
示例5: getDataSources
@Parameters(name = "{index}:{0}")
public static Collection getDataSources() {
List dataSources = new ArrayList<>();
dataSources.add(newH2DataSource());
// MySQL
if (HekateTestProps.is("MYSQL_ENABLED")) {
MysqlDataSource mysql = new MysqlDataSource();
mysql.setURL(HekateTestProps.get("MYSQL_URL"));
mysql.setUser(HekateTestProps.get("MYSQL_USER"));
mysql.setPassword(HekateTestProps.get("MYSQL_PASSWORD"));
dataSources.add(mysql);
// PostgreSQL
if (HekateTestProps.is("POSTGRES_ENABLED")) {
PGSimpleDataSource postgres = new PGSimpleDataSource();
postgres.setUrl(HekateTestProps.get("POSTGRES_URL"));
postgres.setUser(HekateTestProps.get("POSTGRES_USER"));
postgres.setPassword(HekateTestProps.get("POSTGRES_PASSWORD"));
dataSources.add(postgres);
return dataSources;
開發者ID:hekate-io,項目名稱:hekate,代碼行數:31,
示例6: init
@BeforeAll
public static void init() {
開發者ID:orekyuu,項目名稱:Moco,代碼行數:9,
示例7: createSingle
private DataSource createSingle() {
final MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setURL(createURL());
dataSource.setUser(null == user ? "extract" : user);
dataSource.initializeProperties(createProperties());
return dataSource;
開發者ID:ICIJ,項目名稱:extract,代碼行數:12,
示例8: setDataSource
protected static void setDataSource(MysqlDataSource source){
dataSource = source;
開發者ID:WalshyDev,項目名稱:JBA,代碼行數:4,
注:本文中的com.mysql.cj.jdbc.MysqlDataSource類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。