本文整理匯總了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setDatabaseName方法的典型用法代碼示例。如果您正苦於以下問題:Java MysqlDataSource.setDatabaseName方法的具體用法?Java MysqlDataSource.setDatabaseName怎麽用?Java MysqlDataSource.setDatabaseName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mysql.jdbc.jdbc2.optional.MysqlDataSource
的用法示例。
在下文中一共展示了MysqlDataSource.setDatabaseName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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();
}
}
示例3: 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;
}
示例4: 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;
}
示例5: loadFromDB
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public static DataModel loadFromDB() throws Exception {
// Database-based DataModel - MySQLJDBCDataModel
/*
* A JDBCDataModel backed by a PostgreSQL database and accessed via
* JDBC. It may work with other JDBC databases. By default, this class
* assumes that there is a DataSource available under the JNDI name
* "jdbc/taste", which gives access to a database with a
* "taste_preferences" table with the following schema: CREATE TABLE
* taste_preferences ( user_id BIGINT NOT NULL, item_id BIGINT NOT NULL,
* preference REAL NOT NULL, PRIMARY KEY (user_id, item_id) ) CREATE
* INDEX taste_preferences_user_id_index ON taste_preferences (user_id);
* CREATE INDEX taste_preferences_item_id_index ON taste_preferences
* (item_id);
*/
MysqlDataSource dbsource = new MysqlDataSource();
dbsource.setUser("user");
dbsource.setPassword("pass");
dbsource.setServerName("localhost");
dbsource.setDatabaseName("my_db");
DataModel dataModelDB = new MySQLJDBCDataModel(dbsource,
"taste_preferences", "user_id", "item_id", "preference",
"timestamp");
return dataModelDB;
}
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:28,代碼來源:BookRecommender.java
示例6: contextInitialized
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
MysqlDataSource ds = new MysqlDataSource();
ds.setDatabaseName("anychart_db");
ds.setUser("anychart_user");
ds.setPassword("anychart_pass");
context.setAttribute("DBDataSource", ds);
}
開發者ID:anychart-integrations,項目名稱:java-jsp-jdbc-mysql-template,代碼行數:9,代碼來源:DatabaseContextLIstener.java
示例7: prepareMySQL
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private static DataSource prepareMySQL(final Settings settings) {
try {
final MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName(settings.readDatabaseHost());
dataSource.setPortNumber(Integer.parseInt(settings.readDatabasePort()));
dataSource.setDatabaseName(settings.readDatabaseName());
dataSource.setUser(settings.readDatabaseUsername());
dataSource.setPassword(settings.readDatabasePassword());
return dataSource;
} catch (SecurityException e) {
throw new LeargasException(e.getMessage(), e);
}
}
示例8: getAntiExploitConnection
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private Connection getAntiExploitConnection() {
try {
MysqlDataSource mySqlDataSource = new MysqlDataSource();
mySqlDataSource.setDatabaseName(AntiExploit.getInstance().getConfiguration().getConfig().getDatabase());
mySqlDataSource.setUser(AntiExploit.getInstance().getConfiguration().getConfig().getUsername());
mySqlDataSource.setPassword(AntiExploit.getInstance().getConfiguration().getConfig().getPassword());
mySqlDataSource.setServerName(AntiExploit.getInstance().getConfiguration().getConfig().getHost());
mySqlDataSource.setPort(AntiExploit.getInstance().getConfiguration().getConfig().getPort());
return mySqlDataSource.getConnection();
} catch (SQLException ex) {
AntiExploit.getInstance().getLogger().error("Failed to connect to MySQL database!");
ex.printStackTrace();
}
return null;
}
示例9: setup
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
/**
* Setup.
*/
@Before
public void setup()
{
theDataSource = new MysqlDataSource();
theDataSource.setDatabaseName( test_DATABASE_NAME );
theSqlStore = MysqlStore.create( theDataSource, test_TABLE_NAME );
}
示例10: setup
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
/**
* Setup.
*/
@Before
public void setup()
throws
Exception
{
theDataSource = new MysqlDataSource();
theDataSource.setDatabaseName( test_DATABASE_NAME );
theSqlStore = MysqlStore.create( theDataSource, test_TABLE_NAME );
theSqlStore.deleteAll();
}
示例11: CMySQLDataStore
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
/**
* Uses JDBC connection pooling to initialise data source
*/
public CMySQLDataStore(String Sname, int Pnumber, String User, String Pwd, String dbName) {
MysqlDataSource objDs = new MysqlDataSource();
objDs.setServerName(Sname);
objDs.setPortNumber(Pnumber);
objDs.setUser(User);
objDs.setPassword(Pwd);
objDs.setDatabaseName(dbName);
ds = objDs;
}
示例12: createDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private DataSource createDataSource() {
final MysqlDataSource ds = new MysqlDataSource();
ds.setServerName("localhost");
ds.setPortNumber(3306);
ds.setDatabaseName("killbill");
ds.setUser("root");
ds.setPassword("root");
return ds;
}
示例13: createTestDataAccessProvider
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
private static DataAccessProvider createTestDataAccessProvider() {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost");
dataSource.setPortNumber(3306);
dataSource.setDatabaseName("degagetest");
dataSource.setUser("degage");
dataSource.setPassword("DeGaGe");
return new JDBCDataAccessProvider(true, dataSource);
}
示例14: getDataSource
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public MysqlDataSource getDataSource() {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost");
dataSource.setUser("root");
dataSource.setPassword("root");
dataSource.setDatabaseName("rec");
return dataSource;
}
示例15: main
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
public static void main(final String[] args) throws IOException, InterruptedException {
final MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setDatabaseName(DATABASE_NAME);
final JdbcTemplate testdb = new JdbcTemplate(dataSource);
final MongoClient client = new MongoClient("localhost");
final Dependency mysqlDatabaseDependency = new MySqlDatabaseDependency(DATABASE_NAME, testdb);
final Dependency dbDependency = new MongoDBDatabaseDependency(DATABASE_NAME, client);
final Dependency onDiskFileDependency = new OnDiskFileDependency("file");
final DependencyManager dependencyManager = new DependencyManager();
dependencyManager.addDependency(mysqlDatabaseDependency);
dependencyManager.addDependency(dbDependency);
dependencyManager.addDependency(onDiskFileDependency);
final Application application = new Application();
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
application.setResultSet(dependencyManager.evaluate());
}
}, 0L, 3L, TimeUnit.SECONDS);
while (true) {
final CheckResultSet resultSet = application.getResultSet();
if (application.getResultSet() == null) {
continue;
}
Thread.sleep(1000L);
final StringWriter stringWriter = new StringWriter();
WRITER.writeValue(stringWriter, resultSet.summarize(true));
System.out.println(stringWriter);
}
}