Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: database connection with JDBC
In article <8t703q$g79$1_at_nnrp1.deja.com>,
dongbo_at_my-deja.com wrote:
> Hi,
>
> I'm new to JDBC and Oracle. I'm trying to access an Oracle8.1.6 server
> (NT) from another NT box by using jdbc-thin.
>
> First, registered the driver, which looked OK:
> DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
>
> Then, tried to connect to the database server, using
> Connection c = DriverManager.getConnection(
> "jdbc:oracle:thin://42.221.200.200:1521/dw1",
> "username",
> "userID");
> here, "dw1" is my database name. This failed.
>
> Can anybody tell me, what's wrong with my code?
>
> By the way, if I want to load db driver (thin) from method
> Class.forName(String s), what s will look like.
>
> I greatly appreciate all the answers/suggestions. Thanks.
>
> Dongbo Liao
> dliao_at_crl.nmsu.edu
Hi,
I'm also new to JDBC but I solved the problem.
1.In your connectstring, you must comply with jdbc syntax which is "jdbc:oracle:ip.address.or.hostname:port:INSTANCE_NAME"
2.You must provide the instance name and not the db "alias' from tnsnames.ora. Thin driver works over tcp/ip , not sqlnet.
Regards,
Lalaina RAKOTONIAINA
CRM Consultant
Complete Business Solutions Inc.
import java.awt.Frame ;
import oracle.jdbc.driver.* ;
import oracle.sql.* ;
import java.sql.* ;
import java.io.* ;
public class CRMConnection extends Frame implements Serializable {
private static String LOGIN="vero" ;
public String getLogin()
{
return LOGIN ;
}
public void dbConnection()
{
String CONNECT_STRING
= "jdbc:oracle:thin:@207.77.231.120:1521:crm" ;
String PASSWORD="vero" ; Connection MyConnection ; try{ DriverManager.registerDriver(new OracleDriver()) ; MyConnection = DriverManager.getConnection(CONNECT_STRING, this.getLogin(), PASSWORD) ; System.out.println("Succesfully connected to Oracle") ; } catch(Exception ex) { System.out.println("Error in Connection to DB") ; }
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Thu Oct 26 2000 - 05:37:58 CDT
![]() |
![]() |