aspose file tools*
The moose likes JDBC and the fly likes Connecting to remote database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting to remote database " Watch "Connecting to remote database " New topic
Author

Connecting to remote database

saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
Hi,
Please help me with the getconnection method I am stuck in the parameters URL is the mail part.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); -- I have used this database driver.

c=DriverManager.getConnection("url","username","password")

the TNS data with which I am connecting to tha database is

FCFINUPG=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=fcapp3.femcom.net)(PORT=1529))
(CONNECT_DATA=
(SERVICE_NAME=FCFINUPG)
(INSTANCE_NAME=FCFINUPG)
)
)

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

You are using ODBC connection, Did you define an ODBC datasource on your machine ?

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
Shailesh Chandra wrote:You are using ODBC connection, Did you define an ODBC datasource on your machine ?

Shailesh


earlier I used Class.forName("oracle.odbc.driver.OracleDriver"); but it was not working.

the database is not in my local machine. so what should I do suggest me.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I think you did you get what I wanted to ask. I was asking that did you define a DSN or your machine.

If you want to create a type 4 conenction, then you should use class orale.jdbc.driver.OracleDirver


Shailesh
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
hey shailesh

earlier I used Class.forName("oracle.jdbc.driver.OracleDriver"); i then debug it it was not working fine.

then I use Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); I don't know what to do next please help me.
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
I am using below parameter in the forName() method

Class.forName("oracle.jdbc.driver.OracleDriver")
while running I am getting this error

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

any suggestions
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

sun.jdbc.odbc.JdbcOdbcDriver is the JDBC-ODBC bridge. It would be an unusualy thing to do to use this to connect to Oracle. Have a read of this to see why.

Oracle supplies a proper "type 4" driver (if you have not heard that term have a read of ththis) which would be the normal way to connect. If you don't already have it you can get it here; this link also included the documentation and example of how to use it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
so which driver should I use suggest me
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

saurabh dudeja wrote:so which driver should I use suggest me


Didn't I just do that?
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
I have the driver file ojdbc14.jar in my Lib folder where oracle is installed. now what to do suggest me.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I suggest you move it into your classpath.
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
Hey I have included the file ojdbc14.jar in the class path. but still it is showing the error.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What error?
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
while runnning the program its giving error as

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at db_connect_test.<init>(db_connect_test.java:17)
at db_connect_test.main(db_connect_test.java:56)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So its not in your classpath. Where did you put ojdbc14.jar?
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
I right click on my computer(icon) properties--> advance--> environment variables then there system variables path. In that i have put the path.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

saurabh dudeja wrote:I right click on my computer(icon) properties--> advance--> environment variables then there system variables path. In that i have put the path.


The path is not the classpath. Have a read of this.
saurabh dudeja
Greenhorn

Joined: Mar 26, 2009
Posts: 11
hey I got the result it worked thanks a ton
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to remote database