• 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

Connecting to a database

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to establish a connection to a HSQL database using jdbc.
I am loosely following an example from Horstmann's book, Big Java.

I have my properties file database.properties, where i am pretty sure the problem lies. I am not sure what i want to add to the jdbc.url line for it to connect.


The other files include SimpleDataSource which reads the properties from the properties file



And then i attempt to establish a connection to the database.



When i run this test file i get this error

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the properties file, you typed jbdc instead of jdbc - look carefully, the b and the d have been exchanged, for the keys.
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "url" variable is null, which is what the error message says.

That's because nothing ever assigns it a value. And that's because the only code which might assign it a value, the code in your init() method, is never called.
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't spot the spelling mistake, changed it now, it made no differene to the result though.
"Paul Clapham"
I thought i was assigning the string url the property of jbdc.url, and then in TestDB i am calling the getConnection() method which uses the url in it. Or am i missing something?
 
Paul Clapham
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tom davies wrote:I thought i was assigning the string url the property of jbdc.url



Well, no, you're not doing that. The init() method would be doing it, if it were ever called. But nothing ever calls the init() method, so none of the code in it ever runs.
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

tom davies wrote:I thought i was assigning the string url the property of jbdc.url



Well, no, you're not doing that. The init() method would be doing it, if it were ever called. But nothing ever calls the init() method, so none of the code in it ever runs.


Ahh, I see the problem now, i might re write the SimpleDataSource file as well, so i will write back if i have any further problems.
Thank you!
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought i had the answer.
I added this line


Into the TestDB file, so that it actually reads the file first. I still get the same error message though.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic