本文整理汇总了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setUser方法的典型用法代码示例。如果您正苦于以下问题:Java MysqlDataSource.setUser方法的具体用法?Java MysqlDataSource.setUser怎么用?Java MysqlDataSource.setUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.jdbc2.optional.MysqlDataSource
的用法示例。
在下文中一共展示了MysqlDataSource.setUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readTable
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public void readTable(String user, String password, String server){
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser(user);
dataSource.setPassword(password);
dataSource.setServerName(server);
try{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM data_science.books");
while (rs.next()){
int id = rs.getInt("id");
String book = rs.getString("book_name");
String author = rs.getString("author_name");
Date dateCreated = rs.getDate("date_created");
System.out.format("%s, %s, %s, %s\n", id, book, author, dateCreated);
}
rs.close();
stmt.close();
conn.close();
}catch (Exception e){
//Your exception handling mechanism goes here.
}
}
示例2: initDatasource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public void initDatasource(YadaConfiguration config) throws NamingException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setDatabaseName(config.getString("config/database/dbName"));
dataSource.setUser(config.getString("config/database/user"));
dataSource.setPassword(config.getString("config/database/password"));
dataSource.setServerName(config.getString("config/database/server"));
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
builder.bind("java:comp/env/jdbc/yadatestdb", dataSource);
super.dataSource = dataSource;
builder.activate();
// Database
Flyway flyway = new Flyway();
flyway.setLocations("filesystem:schema"); // Where sql test scripts are stored
flyway.setDataSource(dataSource);
flyway.clean();
flyway.migrate();
}
示例3: DataIntegrityTestTool
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public DataIntegrityTestTool(Properties prop) throws Exception{
this.setName("data-integrity-test-thread");
srcDs = new MysqlDataSource();
srcDs.setURL(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_URL));
srcDs.setUser(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_USERNAME));
srcDs.setPassword(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_PASSWROD));
destCount = Integer.parseInt(prop.getProperty(DMLQueryTool.PROP_MSR_DEST_COUNT));
destDs = new MysqlDataSource[destCount];
for(int i=0; i<destCount; i++){
destDs[i] = new MysqlDataSource();
destDs[i].setURL(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_URL, i)));
destDs[i].setUser(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_USERNAME, i)));
destDs[i].setPassword(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_PASSWORD, i)));
}
}
示例4: beforeClass
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception{
initializeTestEnv();
final int sleepCount = 30;
LOGGER.debug("sleep " + sleepCount + "sec for generating enough test data");
for(int i=1; i<=sleepCount; i++){
LOGGER.debug(i + "/" + sleepCount);
Thread.sleep(1000);
}
// create dataSource
dataSource = new MysqlDataSource();
dataSource.setUrl(DB_URL);
dataSource.setUser(DB_USER);
dataSource.setPassword(DB_PW);
}
示例5: setUp
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public void setUp() {
MysqlDataSource mySQLDataSource = new MysqlDataSource();
mySQLDataSource.setUser(SupportDatabaseService.DBUSER);
mySQLDataSource.setPassword(SupportDatabaseService.DBPWD);
mySQLDataSource.setURL("jdbc:mysql://localhost/test");
String envName = "java:comp/env/jdbc/MySQLDB";
SupportInitialContextFactory.addContextEntry(envName, mySQLDataSource);
ConfigurationDBRef config = new ConfigurationDBRef();
Properties properties = new Properties();
properties.put("java.naming.factory.initial", SupportInitialContextFactory.class.getName());
config.setDataSourceConnection(envName, properties);
databaseDSConnFactory = new DatabaseDSConnFactory((ConfigurationDBRef.DataSourceConnection) config.getConnectionFactoryDesc(), config.getConnectionSettings());
}
示例6: getDataSourceLocator
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
@Override
public SQLDataSourceLocator getDataSourceLocator() {
return new SQLDataSourceLocator() {
public DataSource lookup(SQLDataSetDef def) throws Exception {
String url = connectionSettings.getProperty("url");
String user = connectionSettings.getProperty("user");
String password = connectionSettings.getProperty("password");
MysqlDataSource ds = new MysqlDataSource();
ds.setURL(url);
if (!StringUtils.isBlank(user)) {
ds.setUser(user);
}
if (!StringUtils.isBlank(password)) {
ds.setPassword(password);
}
return ds;
}
};
}
示例7: init
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public void init() throws SQLException, RuleBaseException, TeEngineMlException, ParserRunException
{
ruleBaseName = "origdirt";
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("qa-srv");
dataSource.setPort(3308);
dataSource.setUser("db_readonly");
//dataSource.setPassword("");
distSimConnection = dataSource.getConnection();
DistSimParameters originalDirtParameters =
new DistSimParameters("original_dirt.od_templates", "original_dirt.od_rules", LIMIT_DISTSIM_RULES, 2*Constants.DEFAULT_DIRT_LIKE_RESOURCES_CACHE_SIZE, Constants.DEFAULT_DIRT_LIKE_RESOURCES_CACHE_SIZE);
ruleBase = new DistSimRuleBase(distSimConnection,originalDirtParameters,ruleBaseName,parserMode);
parser = ParserFactory.getParser(miniparParameter);
}
示例8: getDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
private static DataSource getDataSource(Driver driver, String url, String user, String password) {
DataSource dataSource;
switch (driver) {
case H2:
JdbcDataSource h2DataSource = new JdbcDataSource();
h2DataSource.setUrl(url);
user = user != null ? user : "";
password = password != null ? password : "";
h2DataSource.setUser(user);
h2DataSource.setPassword(password);
return h2DataSource;
case MYSQL:
MysqlDataSource mysqlDataSource = new MysqlDataSource();
mysqlDataSource.setURL(url);
mysqlDataSource.setUser(user);
mysqlDataSource.setPassword(password);
return mysqlDataSource;
default:
throw new IllegalArgumentException("Unknown database driver");
}
}
示例9: main
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost");
dataSource.setUser("root");
dataSource.setPassword("root");
dataSource.setDatabaseName("rec");
JDBCDataModel dm = new MySQLJDBCDataModel(dataSource,"ratings","userid","itemid","rating","");
UserSimilarity similarity = new PearsonCorrelationSimilarity(dm);
UserNeighborhood neighbor = new NearestNUserNeighborhood(2,similarity, dm);
Recommender recommender = new GenericUserBasedRecommender(dm, neighbor, similarity);
List<RecommendedItem> list = recommender.recommend(1, 3);// recommend
// one item
// to user
// 1
for (RecommendedItem ri : list) {
System.out.println(ri);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: initialSetup
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
/**
* Installs the runway core. This entails creating a new database, creating a
* user for the runway to log in with, and setting any necessary permissions.
*/
public void initialSetup(String rootUser, String rootPass, String rootDb)
{
// Set up the root connection
String rootURL = "jdbc:mysql://" + DatabaseProperties.getServerName() + ":" + DatabaseProperties.getPort() + "/" + rootDb + "?useServerPrepStmts=false";
MysqlDataSource rootSource = new MysqlDataSource();
rootSource.setURL(rootURL);
rootSource.setUser(rootUser);
rootSource.setPassword(rootPass);
this.rootDataSource = rootSource;
this.dropUser();
this.dropDb();
this.createDb(rootDb);
this.createUser();
}
示例11: getDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public static DataSource getDataSource(
String hostName,
int port,
String username,
String passwordClear,
String databaseName)
{
if (hostName == null) { throw new IllegalArgumentException("hostName cannot be null"); }
if (username == null) { throw new IllegalArgumentException("username cannot be null"); }
if (passwordClear == null) { throw new IllegalArgumentException("passwordClear cannot be null"); }
if (databaseName == null) { throw new IllegalArgumentException("databaseName cannot be null"); }
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName(hostName);
ds.setPort(port);
ds.setUser(username);
ds.setPassword(passwordClear);
ds.setDatabaseName(databaseName);
return ds;
}
示例12: openAmberDb
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
public static AmberSession openAmberDb(String dbUrl, String dbUser, String dbPassword, String rootPath) throws InstantiationException, IllegalAccessException,
ClassNotFoundException, SQLException {
DataSource ds = null;
AmberSession sess = null;
try {
MysqlDataSource mds = new MysqlDataSource();
mds.setURL(dbUrl);
mds.setUser(dbUser);
mds.setPassword(dbPassword);
ds = mds;
sess = openAmberDb(ds, rootPath);
} catch (Throwable e) {
h2Test = true;
// This is for build integration site which does not have
// direct access to the mysql data source.
DriverManager.registerDriver(new org.h2.Driver());
dbUrl = "jdbc:h2:" + Paths.get(".").resolve("graph") + ";MVCC=true;DATABASE_TO_UPPER=false";
dbUser = "garfield";
dbPassword = "odde";
ds = JdbcConnectionPool.create(dbUrl, dbUser, dbPassword);
sess = openAmberDb(ds, rootPath);
}
return sess;
}
示例13: getAdminDatasource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
/**
* @return A Connection to the admin_test database
* @throws javax.servlet.ServletException
*/
public static DataSource getAdminDatasource() throws ServletException {
DataSource dataSource = null;
try {
// unit testing...
MysqlDataSource ds = new MysqlDataSource();
//ds.setDriverClass("com.mysql.jdbc.Driver");
ds.setServerName("localhost");
ds.setDatabaseName("admin");
ds.setUser("root");
ds.setPassword("**pasword**");
dataSource = ds;
} catch (Exception ex) {
throw new ServletException("Cannot retrieve jdbc:mysql://localhost/admin", ex);
}
return dataSource;
}
示例14: setUpService
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
@Before
public void setUpService() {
MockitoAnnotations.initMocks(this);
CaArrayUsernameHolder.setUser(STANDARD_USER);
final ProjectManagementServiceBean pmsBean = new ProjectManagementServiceBean();
pmsBean.setProjectDao(this.daoFactoryStub.getProjectDao());
pmsBean.setFileDao(fileDao);
pmsBean.setSampleDao(this.daoFactoryStub.getSampleDao());
pmsBean.setSearchDao(this.daoFactoryStub.getSearchDao());
pmsBean.setVocabularyDao(this.daoFactoryStub.getVocabularyDao());
locatorStub = ServiceLocatorStub.registerEmptyLocator();
locatorStub.addLookup(FileAccessService.JNDI_NAME, this.fileAccessServiceStub);
locatorStub.addLookup(GenericDataService.JNDI_NAME, this.genericDataService);
final MysqlDataSource ds = new MysqlDataSource();
final Configuration config = hibernateHelper.getConfiguration();
ds.setUrl(config.getProperty("hibernate.connection.url"));
ds.setUser(config.getProperty("hibernate.connection.username"));
ds.setPassword(config.getProperty("hibernate.connection.password"));
locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds);
this.projectManagementService = pmsBean;
locatorStub.addLookup(ProjectManagementService.JNDI_NAME, this.projectManagementService);
hibernateHelper.setFiltersEnabled(false);
this.transaction = hibernateHelper.beginTransaction();
}
示例15: createPermissionsManagementService
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //导入方法依赖的package包/类
private PermissionsManagementService createPermissionsManagementService(GenericDataService genericDataServiceStub) {
final CaArrayDaoFactory daoFactory = CaArrayDaoFactory.INSTANCE;
final PermissionsManagementServiceBean bean = new PermissionsManagementServiceBean();
bean.setHibernateHelper(this.hibernateHelper);
bean.setCollaboratorGroupDao(daoFactory.getCollaboratorGroupDao());
bean.setSearchDao(daoFactory.getSearchDao());
final ServiceLocatorStub locatorStub = ServiceLocatorStub.registerEmptyLocator();
locatorStub.addLookup(GenericDataService.JNDI_NAME, genericDataServiceStub);
final MysqlDataSource ds = new MysqlDataSource();
final Configuration config = this.hibernateHelper.getConfiguration();
ds.setUrl(config.getProperty("hibernate.connection.url"));
ds.setUser(config.getProperty("hibernate.connection.username"));
ds.setPassword(config.getProperty("hibernate.connection.password"));
locatorStub.addLookup("java:jdbc/CaArrayDataSource", ds);
bean.setGenericDataService(genericDataServiceStub);
return bean;
}