Connect to an Oracle database with JDBC

 
 
Oracle Corporation has released a free 100% JAVA driver. It is available at their Web site. According to the security rule, the Oracle server must be on the same machine as the Web server, since the communication with the Applet is done through Sockets. This is not always possible, so you will need something called a Connection Manager (from Oracle) or DBAnywhere from Symantec (demo version available for testing) to act as a bridge between the client, the Web server and the Database server.
import java.sql.*;

public class connectToOracle extends java.applet.Applet {
  Driver driver;
  Connection conn = null;
  static String driverUsed =
     "oracle.jdbc.driver.OracleDriver";
  static String serverAddress =
     "jdbc:oracle:thin:scott/tiger@www.myCompany.com:1243:myInstance";
     // jdbc:oracle:thin is the driver used
     // scott/tiger is user/password
     // www.myServer.com  is  the same machine from where the Applet was loaded
     // 1234  is the port used
     // myInstance  is  where my data is

  public void init(){
    makeConnection(serverAddress);
    }
      
  public void makeConnection(String svr) {
    try {
      System.out.println("Loading ... " + driverUsed);
      driver =
         (Driver)Class.forName(driverUsed).newInstance();
      System.out.println("Connecting ... " + svr);
      conn =
         DriverManager.getConnection(svr);
      System.out.println("Ready.");
      }
    catch (Exception e) {
      e.printStackTrace();
      }
    }
   }
NOTE: With Microsoft IEv4, you may have an Exception talking about "No more data on socket", simply *TURN OFF* the JIT to solve the problem.

Also check the parameter sqlnet.expiretime in the SQLNET.ORA file, if there is one try to remove it or increase the value (Oracle 7.3).

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值