⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rebinddatasource.java

📁 精通Java核心技术的随书源代码
💻 JAVA
字号:
// ==================== Program Discription ==========================
// 程序名称:示例13-6 : RebindDataSource.java
// 程序目的:数据源的重新绑定
// ==============================================================
import com.inet.tds.TdsDataSource;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
import java.sql.* ;
import javax.sql.* ;

public class RebindDataSource 
{
    // define the relevant parameters for this datasource
    private String serverName = "persistentjava.com";
    private int portNumber = 1434;      // new port number
    private String login = "sun";         // new username and password combination
    private String password = "java";
    private String databaseName = "ds";  // even a new database name

    private String filePath = "jdbc/datasource";

    public RebindDataSource () 
    {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
               "com.sun.jndi.fscontext.RefFSContextFactory");
        try {
          Context ctx = new InitialContext(env);
          TdsDataSource ds = new TdsDataSource();

          ds.setServerName(serverName);
          ds.setPortNumber(portNumber);
          ds.setDatabaseName(databaseName);
          ds.setUser(login);
          ds.setPassword(password);
          ds.setDescription("JDBC DataSource Connection ");

          // call the rebind method with the new DataSource.
          ctx.rebind(filePath, ds);
          ctx.close();
        } 
        catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
    }

    public static void main(String args[]) {
        new RebindDataSource();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -