com.mysql.jdbc.jdbc2.optional.MysqlDataSource类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(616)

本文整理了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource类的一些代码示例,展示了MysqlDataSource类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MysqlDataSource类的具体详情如下:
包路径:com.mysql.jdbc.jdbc2.optional.MysqlDataSource
类名称:MysqlDataSource

MysqlDataSource介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("scott");
dataSource.setPassword("tiger");
dataSource.setServerName("myDBHost.example.org");

代码示例来源:origin: killbill/killbill

private DataSource getRawMysqlDataSource(final String dbName, final String user, final String pwd) {
  final com.mysql.jdbc.jdbc2.optional.MysqlDataSource rawSource = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
  rawSource.setDatabaseName(dbName);
  rawSource.setUser(user);
  rawSource.setPassword(pwd);
  rawSource.setPort(3306);
  rawSource.setURL("jdbc:mysql://localhost:3306/killbill?createDatabaseIfNotExist=true&allowMultiQueries=true");
  return rawSource;
}

代码示例来源:origin: alibaba/nacos

MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setConnectTimeout(CONNECT_TIMEOUT_MS);
dataSource.setSocketTimeout(CONNECT_TIMEOUT_MS);
dataSource.setUser(config.getUser());
dataSource.setPassword(config.getPwd());
dataSource.setLoginTimeout(1);
dataSource.setServerName(ip.getIp());
dataSource.setPort(ip.getPort());
connection = dataSource.getConnection();
CONNECTION_POOL.put(key, connection);

代码示例来源:origin: prestodb/presto

@Inject
public MysqlDaoProvider(DbResourceGroupConfig config)
{
  requireNonNull(config, "DbResourceGroupConfig is null");
  MysqlDataSource dataSource = new MysqlDataSource();
  dataSource.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
  this.dao = Jdbi.create(dataSource)
      .installPlugin(new SqlObjectPlugin())
      .onDemand(ResourceGroupsDao.class);
}

代码示例来源:origin: boonproject/boon

protected void connect() {
  try {
    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setURL(url);
    dataSource.setPassword(password);
    dataSource.setUser(userName);
    connection = dataSource.getConnection();
    connection.setAutoCommit(true);
    closed = false;
    totalConnectionOpen++;
  } catch (SQLException sqlException) {
    this.closed = true;
    connection = null;
    handle("Unable to connect", sqlException);
  }
}

代码示例来源:origin: jerolba/jfleet

@Override
public DataSource get() {
  MysqlDataSource mysqlds = new MysqlDataSource();
  mysqlds.setUrl(prop.getProperty("urlConnection"));
  mysqlds.setUser(prop.getProperty("user"));
  mysqlds.setPassword(prop.getProperty("password"));
  return mysqlds;
}

代码示例来源:origin: com.carrotsearch/junit-benchmarks

@Override
protected Connection createConnection() throws SQLException
{
  final MysqlDataSource ds = new MysqlDataSource();
  ds.setURL(dbUrl);
  Connection results = ds.getConnection();
  results.setAutoCommit(false);
  return results;
}

代码示例来源:origin: stackoverflow.com

MysqlDataSource mysqlDS = new MysqlDataSource();
mysqlDS.setUseSSL(true);
mysqlDS.setRequireSSL(true);
mysqlDS.setClientCertificateKeyStoreUrl(".../keystore");
mysqlDS.setClientCertificateKeyStorePassword("keystore-pw");
mysqlDS.setTrustCertificateKeyStoreUrl(".../truststore");
mysqlDS.setTrustCertificateKeyStorePassword("truststore-pw");
mysqlDS.setServerName("server");
mysqlDS.setPort(3306);
mysqlDS.setDatabaseName("databasename");
Connection connection = mysqlDS.getConnection("user", "password");

代码示例来源:origin: stackoverflow.com

String connectionUrl = "jdbc:mysql://localhost:3307/mydb";

com.mysql.jdbc.jdbc2.optional.MysqlDataSource mds =
    new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
mds.setUrl(connectionUrl);

代码示例来源:origin: ops4j/org.ops4j.pax.jdbc

private void setProperties(MysqlDataSource ds, Properties properties) throws SQLException {
  Properties props = (Properties) properties.clone();
  String url = (String) props.remove(DataSourceFactory.JDBC_URL);
  if (url != null) {
    ds.setUrl(url);
  }
  String databaseName = (String) props.remove(DataSourceFactory.JDBC_DATABASE_NAME);
  if (databaseName == null && url == null) {
    throw new SQLException("missing required property "
      + DataSourceFactory.JDBC_DATABASE_NAME);
  }
  ds.setDatabaseName(databaseName);
  String password = (String) props.remove(DataSourceFactory.JDBC_PASSWORD);
  ds.setPassword(password);
  String portNumber = (String) props.remove(DataSourceFactory.JDBC_PORT_NUMBER);
  if (portNumber != null) {
    ds.setPortNumber(Integer.parseInt(portNumber));
  }
  String serverName = (String) props.remove(DataSourceFactory.JDBC_SERVER_NAME);
  ds.setServerName(serverName);
  String user = (String) props.remove(DataSourceFactory.JDBC_USER);
  ds.setUser(user);
  if (!props.isEmpty()) {
    BeanConfig.configure(ds, props);
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception {
  MysqlDataSource db = new MysqlDataSource();
  db.setDatabaseName("test");
  Connection conn = db.getConnection("test", "test");

  ResultSet res = conn.prepareStatement("SELECT * FROM thing").executeQuery();
  res.next();
  System.out.println("Get a int as a string: " + res.getString("a_int"));

}

代码示例来源:origin: stackoverflow.com

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
//...
MysqlDataSource mysql = (MysqlDataSource) context.lookup("jdbc/MySQLDataSource");
mysql.setRewriteBatchedStatements(true);
Connection conn = mysql.getConnection();

代码示例来源:origin: stackoverflow.com

MysqlDataSource ds = new MysqlDataSource();
ds.setUrl(dbUrl);
DBI dbi = new DBI(ds);

代码示例来源:origin: boonproject/boon

protected void connect() {
  try {
    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setURL(url);
    dataSource.setPassword(password);
    dataSource.setUser(userName);
    connection = dataSource.getConnection();
    connection.setAutoCommit(true);
    closed = false;
    totalConnectionOpen++;
  } catch (SQLException sqlException) {
    this.closed = true;
    connection = null;
    handle("Unable to connect", sqlException);
  }
}

代码示例来源:origin: stackoverflow.com

public class JavaApplication {

private static final String DATABASE_URL = "jdbc:mysql://localhost/test?characterEncoding=utf8";
private static final String DATABASE_USER = "root";
private static final String DATABASE_PASSWORD = "";
private static Connection con;
public static void main(String[] args) {
  try {
    Timestamp date = new Timestamp(System.currentTimeMillis());
    MysqlDataSource ds = new MysqlDataSource();
    ds.setUrl(DATABASE_URL);
    ds.setUser(DATABASE_USER);
    ds.setPassword(DATABASE_PASSWORD);
    con = ds.getConnection();
    PreparedStatement ps = con.prepareStatement("INSERT INTO tablename (date) VALUES (?)");
    ps.setTimestamp(1, date);
    ps.executeUpdate();
    ps = con.prepareStatement("SELECT * FROM tablename");
    ResultSet rs = ps.executeQuery();
    while(rs.next()){
      System.out.println("Date in database: "+rs.getTimestamp("date"));
      System.out.println("Time difference between server and database record in seconds: "+(rs.getTimestamp("date").getTime()-System.currentTimeMillis())/1000);
    }
  } catch (SQLException ex) {
    ex.printStackTrace();
  }
}

代码示例来源:origin: com.facebook.presto/presto-resource-group-managers

@Inject
public MysqlDaoProvider(DbResourceGroupConfig config)
{
  requireNonNull(config, "DbResourceGroupConfig is null");
  MysqlDataSource dataSource = new MysqlDataSource();
  dataSource.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
  this.dao = Jdbi.create(dataSource)
      .installPlugin(new SqlObjectPlugin())
      .onDemand(ResourceGroupsDao.class);
}

代码示例来源:origin: org.scijava/junit-benchmarks

@Override
protected Connection createConnection() throws SQLException
{
  final MysqlDataSource ds = new MysqlDataSource();
  ds.setURL(dbUrl);
  Connection results = ds.getConnection();
  results.setAutoCommit(false);
  return results;
}

代码示例来源:origin: org.wisdom-framework/mysql-connector-java

@Override
public DataSource newDataSource() throws SQLException {
  return new MysqlDataSource();
}

代码示例来源:origin: games647/LagMonitor

public void saveTps(float tps) {
    try (Connection con = dataSource.getConnection();
       PreparedStatement stmt = con.prepareStatement("INSERT INTO " + prefix
           + TPS_TABLE + " (tps) VALUES (?)")) {
      stmt.setFloat(1, tps);
      stmt.execute();
    } catch (SQLException sqlEx) {
      logger.log(Level.SEVERE, "Error saving tps to database", sqlEx);
      logger.log(Level.SEVERE, "Using this data {0}", new Object[]{tps});
    }
  }
}

代码示例来源:origin: stackoverflow.com

MysqlDataSource dataSource = new MysqlDataSource();
 dataSource.setDatabaseName("xyz");
 dataSource.setUser("xyz");
 dataSource.setPassword("xyz");
 dataSource.setServerName("xyz.yourdomain.com");

相关文章