Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

the url cannot be null while using database.properties with JDBC  RSS feed

 
VarunS Singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output :
java.sql.SQLException: The url cannot be null
BUILD SUCCESSFUL (total time: 1 second)

The properties file is used is database.properties:

jdbc.drivers = com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/Sampledb
jdbc.username=root
jdbc.password=tiger
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding:
System.out.println(url);

That will check if the problem is in reading the properties or the database code. My guess is the database.properties file isn't where the code is expecting it to be.

Also try:


This will show you the directory Java expects the property file to be in.
 
VarunS Singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried what you asked:
The output shows as follows respectively :

null
C:\Users\Varun\Desktop\IIHT_TextBookExample\database.properties
java.sql.SQLException: The url cannot be null
 
VarunS Singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the problem is that it is not locating the file. I changed the name of my properties file to d.properties.

It gives Filenotfound Exception
 
Knute Snortum
Sheriff
Posts: 4193
122
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this correct?

Should that be "jdbc.drivers?
 
Knute Snortum
Sheriff
Posts: 4193
122
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also...

should be...

(no spaces)?
 
VarunS Singh
Ranch Hand
Posts: 31
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok....its done , there was this database.properties already present in the directory which I had to delete as there was different database connection info in it.

thanks for the help ...everyone......Keep Coding
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37384
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting what the problem turned out to be.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!