這是DB連接字符串到Oracle的Java連接到Oracle網格 - DB連接字符串
ABCSERVICE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = servername1-vip.test.ampf.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = servername2-vip.test.ampf.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = servername3-vip.test.ampf.com)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ABCSERVICE)
)
)
我使用的服務器的一個和conenction工作。我需要在具有用於完成連接字符串幫助上述Oracle網格 之一,所以,如果有故障轉移的下一個服務器拿起
連接字符串一個服務器
的jdbc:神諭:薄: @ // servername1-vip.test.ampf.com/ABCSERVICE
計劃單服務器
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class DBConnection {
public static void executeQuery(final Connection connection) throws SQLException
{
try{
// test the conenction here and it works
}
}catch (SQLException e) {
System.out.println(e);
}
}
public static void main(final String[] args) throws Exception{
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "servername1-vip.test.ampf.com";
String portNumber = "1521";
String serviceName = "ABCSERVICE";
String url = "jdbc:oracle:thin:@//" + serverName + ":" + portNumber + "/" + serviceName;
System.out.println(url);
String username = "userName";
String password = "passWord";
connection = DriverManager.getConnection(url, username, password);
executeQuery(connection);
} catch (ClassNotFoundException e) {
System.out.println(e);
} catch (SQLException e) {
// Could not connect to the database
System.out.println(e);
}
}
}