本文整理匯總了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setPassword方法的典型用法代碼示例。如果您正苦於以下問題:Java MysqlDataSource.setPassword方法的具體用法?Java MysqlDataSource.setPassword怎麽用?Java MysqlDataSource.setPassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mysql.jdbc.jdbc2.optional.MysqlDataSource
的用法示例。
在下文中一共展示了MysqlDataSource.setPassword方法的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: 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");
}
}
示例8: 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();
}
}
示例9: 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();
}
示例10: 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;
}
示例11: getAdminUnitTestDatasource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
/**
* @return A Connection to the admin_test database
* @throws javax.servlet.ServletException
*/
public static DataSource getAdminUnitTestDatasource() throws ServletException {
DataSource dataSource = null;
try {
// unit testing...
MysqlDataSource ds = new MysqlDataSource();
//ds.setDriverClass("com.mysql.jdbc.Driver");
ds.setServerName("jdbc:mysql://localhost/admin_test");
ds.setUser("root");
ds.setPassword("**pasword**");
dataSource = ds;
} catch (Exception ex) {
throw new ServletException("Cannot retrieve jdbc:mysql://localhost/admin_test", ex);
}
return dataSource;
}
示例12: 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;
}
示例13: 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();
}
示例14: 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;
}
示例15: 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());
}