//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.