Jump to content
  • Advertisement
Sign in to follow this  
ju2wheels

[java] JDBC

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi im trying to connect to an oracle database using JDBC. Im currently doing the following to get the connection: DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); con = DriverManager.getConnection ("jdbc:oracle:thin:@" + server + ":" + port + ":" + sid, usernm, passwd); This requires me to include the oracle db driver that I specified above which I got from someone at work. Its a pretty big driver package and I was trying to find a more generic way to connect. How can I find out what db drivers JDBC 3 has incorporated in it already? Can I omit the register driver line above and just use jdbc:server... and get it to automatically find a driver that works to connect to the database so I dont have to include the oracle package I was given. As I read I thought JDBC had basic functionality that worked on just about any database type without the need for third party stuff like the one I was given.

Share this post


Link to post
Share on other sites
Advertisement
I solved my problem (well at least the first half... I can play with it from here). I used the "jdbc.driver" system property to tell me the available drivers.

Share this post


Link to post
Share on other sites
If you need to find a driver for a database here is a good link : http://developers.sun.com/product/jdbc/drivers

The generic driver is sun.jdbc.odbc.JdbcOdbcDriver. It doesn't work with all database because it's generic, but usually it gives good results.

For registring the driver, you should not do it yourself with :
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
because the drivers register themselves to the driverManager!
All you have to do for the driver to register itself is loading the driver class in the jvm. You can do that with that line :
Class.forName(Driver_name).newInstance();

(With badly implemented driver you might have to do Class.forName(nomDriver).newInstance(); )

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!