本文整理匯總了Java中com.mysql.jdbc.jdbc2.optional.MysqlDataSource.setServerName方法的典型用法代碼示例。如果您正苦於以下問題:Java MysqlDataSource.setServerName方法的具體用法?Java MysqlDataSource.setServerName怎麽用?Java MysqlDataSource.setServerName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mysql.jdbc.jdbc2.optional.MysqlDataSource
的用法示例。
在下文中一共展示了MysqlDataSource.setServerName方法的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: 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);
}
示例4: 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();
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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
示例9: setUp
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; //導入方法依賴的package包/類
@BeforeClass
static public void setUp() {
dataSource = new MysqlDataSource();
dataSource.setServerName("relational.fit.cvut.cz"); // Public read-only database for testing
dataSource.setUser("guest");
dataSource.setPassword("relational");
}
示例10: 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);
}
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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);
}
示例15: 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;
}