当前位置:首页>编程日记>正文

java datasource mysql_Java MysqlDataSource類代碼示例

本文整理匯總了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;未經允許,請勿轉載。


http://www.coolblog.cn/news/29448215299266f0.html

相关文章:

  • asp多表查询并显示_SpringBoot系列(五):SpringBoot整合Mybatis实现多表关联查询
  • s7day2学习记录
  • 【求锤得锤的故事】Redis锁从面试连环炮聊到神仙打架。
  • 矿Spring入门Demo
  • 拼音怎么写_老师:不会写的字用圈代替,看到孩子试卷,网友:人才
  • Linux 实时流量监测(iptraf中文图解)
  • Win10 + Python + GPU版MXNet + VS2015 + RTools + R配置
  • 美颜
  • shell访问php文件夹,Shell获取某目录下所有文件夹的名称
  • 如何优雅的实现 Spring Boot 接口参数加密解密?
  • LeCun亲授的深度学习入门课:从飞行器的发明到卷积神经网络
  • Mac原生Terminal快速登录ssh
  • java受保护的数据与_Javascript类定义语法,私有成员、受保护成员、静态成员等介绍...
  • mysql commit 机制_1024MySQL事物提交机制
  • 支撑微博千亿调用的轻量级RPC框架:Motan
  • jquery 使用小技巧
  • 2019-9
  • 法拉利虚拟学院2010 服务器,法拉利虚拟学院2010
  • vscode pylint 错误_将实际未错误的py库添加到pylint白名单
  • 科学计算工具NumPy(3):ndarray的元素处理
  • 工程师在工作电脑存 64G 不雅文件,被公司开除后索赔 41 万,结果…
  • linux批量创建用户和密码
  • newinsets用法java_Java XYPlot.setInsets方法代碼示例
  • js常用阻止冒泡事件
  • 气泡图在开源监控工具中的应用效果
  • 各类型土地利用图例_划重点!国土空间总体规划——土地利用
  • php 启动服务器监听
  • dubbo简单示例
  • 【设计模式】 模式PK:策略模式VS状态模式
  • [iptables]Redhat 7.2下使用iptables实现NAT
  • Ubuntu13.10:[3]如何开启SSH SERVER服务
  • CSS小技巧——CSS滚动条美化
  • JS实现-页面数据无限加载
  • 阿里巴巴分布式服务框架 Dubbo
  • 最新DOS大全
  • Django View(视图系统)
  • 阿里大鱼.net core 发送短信
  • 程序员入错行怎么办?
  • 两张超级大表join优化
  • 第九天函数
  • Linux软件安装-----apache安装
  • HDU 5988 最小费用流
  • Sorenson Capital:值得投资的 5 种 AI 技术
  • 《看透springmvc源码分析与实践》读书笔记一
  • 正式开课!如何学习相机模型与标定?(单目+双目+鱼眼+深度相机)
  • Arm芯片的新革命在缓缓上演
  • nagios自写插件—check_file
  • python3 错误 Max retries exceeded with url 解决方法
  • 行为模式之Template Method模式
  • 通过Spark进行ALS离线和Stream实时推荐