• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC connection with oracle 10g

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello.
my code:



it throws error:
Exception in thread "main" java.lang.NullPointerException
at edu.trialpackage.databaseConnection.OracleConnect.main(OracleConnect.java:19)



can you please tell me where i am wrong..
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure about your approach to connect to DB (I really haven't tried it myself). But I suggest you to use DriverManager (for standalone applications) to get the connection to the DB, which is the preferred method. Check the JDBC tutorial
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 19 is "Statement st = con.createStatement();" which can only mean that "con" is null. That means that d.connect("jdbc:oracle:thin:@oracle:8080:STUDENTINFO",p) returns null, which in turn means the URL is wrong.

I second Vijitha's advice to use DriverManager: If there's a problem this will throw an SQLException instead of returning null.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For your information, class oracle.jdbc.driver.OracleDriver has been deprecated for many years now.
Its replacement is oracle.jdbc.OracleDriver.

Good Luck,
Avi.
 
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic