📄 binddatasource.java
字号:
// ==================== Program Discription ==========================
// 程序名称:示例13-4 : BindDataSource.java
// 程序目的:注册JDBC 数据源
// ==============================================================
import com.inet.tds.TdsDataSource;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
import java.sql.* ;
import javax.sql.* ;
public class BindDataSource {
// define the parameters for the datasource
private String serverName = "persistentjava.com";
private int portNumber = 1433;
private String login = "java";
private String password = "sun";
private String databaseName = "jdbc";
private String filePath = "jdbc/datasource";
public BindDataSource()
{
// create a Hashtable to pass the parameters
Hashtable env = new Hashtable();
env.put( Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
try {
// Create the initial context
Context ctx = new InitialContext(env);
// create the actual DataSource and set the parameters
TdsDataSource ds = new TdsDataSource();
ds.setServerName(serverName);
ds.setPortNumber(portNumber);
ds.setDatabaseName(databaseName);
ds.setUser(login);
ds.setPassword(password);
ds.setDescription("JDBC DataSource Connection");
// bind the DataSource object to the name we selected earlier
ctx.bind(filePath, ds);
ctx.close();
}
catch (Exception ex) {
System.err.println(ex.getMessage());
}
}
public static void main(String args[]) {
new BindDataSource ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -