📄 datasourceserver.java
字号:
package datasource;
import java.sql.*;
import javax.sql.*;
import oracle.jdbc.pool.OracleDataSource;
import javax.naming.*;
import java.util.*;
/**
* A class to create a DataSource and bind it to a directory.
*/
public class DataSourceServer {
static ResourceBundle bundle = null;
public static void main(String[] args) {
bundle = ResourceBundle.getBundle("DataSource");
try {
// create and store parameters which are used to create the context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
bundle.getString("datasource.factory"));
env.put(Context.PROVIDER_URL, bundle.getString("datasource.url"));
// create the context
Context context = new InitialContext(env);
// Create a DataSource object
OracleDataSource dataSource = new OracleDataSource();
// set the connection parameters
String s = bundle.getString("datasource.username");
dataSource.setUser(s);
s = bundle.getString("datasource.password");
dataSource.setPassword(s);
s = bundle.getString("datasource.drivertype");
dataSource.setDriverType(s);
s = bundle.getString("datasource.netprotocol");
dataSource.setNetworkProtocol(s);
s = bundle.getString("datasource.server");
dataSource.setServerName(s);
dataSource.setPortNumber(getPort());
s = bundle.getString("datasource.databasename");
dataSource.setDatabaseName(s);
// get the name
String bindName = bundle.getString("datasource.bindname");
// bind the DataSource with the name
context.rebind(bindName, dataSource);
System.out.println("DataSource completed");
} catch (Exception e) {
e.printStackTrace();
}
}
static int getPort() throws NumberFormatException {
String s = bundle.getString("datasource.port");
return Integer.parseInt(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -