• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Unable to load resource

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

//DBconnection.java

private static Connection con = null;
private static Properties databaseProperties = new Properties();

static{
try {
databaseProperties.load(DBConnection.class.getClassLoader().getResourceAsStream("dbInfo.properties"));
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
Properties dbProps = new Properties();
dbProps.put("user", databaseProperties.getProperty("user"));
dbProps.put("password", databaseProperties.getProperty("password"));
String dbURL="jdbc:sybase:Tds:"+databaseProperties.getProperty("server")+":"+databaseProperties.getProperty("port");
con = DriverManager.getConnection(dbURL, dbProps);
System.out.println("dbconnection = "+con);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
--------------------------
while running The above web applicatoin it gives:

java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:418)
at java.util.Properties.load0(Properties.java:337)
at java.util.Properties.load(Properties.java:325)
at monitor.util.DBConnection.<clinit>(DBConnection.java:30)


here line 30 is: databaseProperties.load(DBConnection.class.getClassLoader().getResourceAsStream("dbInfo.properties"));

Any suggestion how to avoid the above exception ?
The dbInfo.properties file is alreay present at the location where this DBconnection.java file is available.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, at runtime, the dbInfo.properties file needs to be where the DBConnection.class file is, not the .java file. If you're building and running this from an IDE, it can be tricky making sure all your bits are in the right place when you run the program. If you're packing this code into a JAR file, then the properties file needs to go into that JAR as well.
 
Ramesh Kumar Swarnkar
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ernest.
Actually had kept in folder where I had the DBConnection.class file. but while I moved to the out of that folder and kept inside Class folder (that is 1 level up), it works fine now
Filename: img.bmp
Description: screen-shot
File size: 102 Kbytes
 
Sheriff
Posts: 22854
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your code you're using dbInfo.properties, while the file is called vectorDB.properties.

Also, the properties file is not located in the same folder (or a subfolder) as the class file, so you should try using an absolute path: /vectorDB.properties.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic