當前位置: 首頁>>代碼示例>>Java>>正文


Java MysqlDataSource.setDatabaseName方法代碼示例

本文整理匯總了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();
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:18,代碼來源:YadaTestConfig.java

示例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();
    }

}
 
開發者ID:laozhaokun,項目名稱:movie_recommender,代碼行數:24,代碼來源:RecommenderWithMahout.java

示例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;
}
 
開發者ID:mathesonventures,項目名稱:wildebeest,代碼行數:22,代碼來源:MySqlUtil.java

示例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;
}
 
開發者ID:chrisekelley,項目名稱:zeprs,代碼行數:21,代碼來源:DatabaseUtils.java

示例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);
    }
}
 
開發者ID:IWSDevelopers,項目名稱:iws,代碼行數:16,代碼來源:Leargas.java

示例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;
}
 
開發者ID:LXGaming,項目名稱:AntiExploit,代碼行數:16,代碼來源:MySQL.java

示例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 );
}
 
開發者ID:infogrid-org,項目名稱:infogrid-graphdb,代碼行數:12,代碼來源:AbstractStoreMeshBaseTest.java

示例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();
}
 
開發者ID:infogrid-org,項目名稱:infogrid-graphdb,代碼行數:15,代碼來源:AbstractModelChangeTest.java

示例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;

}
 
開發者ID:bcdy23,項目名稱:CZ3003_Backend,代碼行數:17,代碼來源:CMySQLDataStore.java

示例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;
}
 
開發者ID:killbill,項目名稱:killbill-bitcoin-plugin,代碼行數:10,代碼來源:TestPendingPaymentDao.java

示例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);
}
 
開發者ID:degage,項目名稱:degapp,代碼行數:12,代碼來源:JDBCDataAccess.java

示例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;
}
 
開發者ID:laozhaokun,項目名稱:movie_recommender,代碼行數:9,代碼來源:DBUtil.java

示例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);
    }
}
 
開發者ID:indeedeng,項目名稱:status,代碼行數:38,代碼來源:Application.java


注:本文中的com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setDatabaseName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。