By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,543 Members | 2,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,543 IT Pros & Developers. It's quick & easy.

Runtime errors while getting property file in netbeans 6.5

bansari
P: 20
This Is My CODE::
Expand|Select|Wrap|Line Numbers
  1. package assign21;
  2.  
  3. import java.io.FileInputStream;
  4. import java.util.*;
  5. import java.sql.*;
  6.  
  7.  
  8. public class WithPropertyFile
  9. {
  10.  
  11.     String driver=null;
  12.  
  13.     String url = null;
  14.  
  15.     String username = null;
  16.     String psword = null;
  17.  
  18.     String propFile="D:/Bansari_Trainee/bansari_assign/Assign 2/Assign 2.1/assign2.1/src/assign21/DataProperty.properties";
  19.     public static String databaseInfo = "";
  20.     public static Connection connect;
  21.     public static ResultSet result;
  22.     public static ResultSet result1;
  23.     ResultSetMetaData rsMetadata;
  24.     int iColumnCount;
  25.     public static Statement statementObject;
  26.     PropertyResourceBundle pBundle = null;
  27.  
  28.  
  29.     public WithPropertyFile() {
  30.  
  31.     try{
  32.  
  33.         System.out.println("\n--Properties File Path  is ----"+propFile);
  34.         pBundle = new PropertyResourceBundle(new FileInputStream(propFile));
  35.                     databaseInfo =  (pBundle.handleGetObject("POSTGRE")).toString();
  36.                     System.out.println("\nOpening database-------------\n");
  37.                     System.out.print(propFile);
  38.                     if (!databaseInfo.equals(null)){
  39.  
  40.     StringTokenizer st = new StringTokenizer(databaseInfo);
  41.  
  42.         driver = st.nextToken();
  43.         System.out.println("\nDriver =>" + driver);
  44.         url = st.nextToken();
  45.         username = st.nextToken();
  46.         psword = st.nextToken();
  47.  
  48.         System.out.println("\nurl = " + url + "\npassword = " + psword);
  49.                     }
  50.  
  51.  
  52.     }
  53.  catch(Exception e){e.printStackTrace();}
  54.  
  55.     }
  56.  
  57. public WithPropertyFile(String propfile){
  58.         propFile=propfile;
  59.         new WithPropertyFile();
  60.     }
  61.  
  62. public void open()
  63.         {
  64.             try{
  65.  
  66.  
  67.                             Class.forName(driver);
  68.                             // create connection
  69.                                connect = DriverManager.getConnection(url,username,psword);
  70.                                 statementObject = connect.createStatement();
  71.              //                  result = statementObject.executeQuery("SELECT * FROM usermaster");
  72.                             System.out.println("Your Connection is Established...");
  73.  
  74.  
  75.  
  76.         }
  77.         catch(Exception e)
  78.             {
  79.                 e.printStackTrace();
  80.             }
  81.         }
  82.  
  83.  
  84.     public void close()
  85.         {
  86.         try{
  87.             connect.close();
  88.         }
  89.         catch(Exception e)
  90.             {
  91.                 e.printStackTrace();
  92.             }
  93.     }
  94.  
  95. }
  96.  
  97.  class DBConnection {
  98.  
  99.     public static void main(String args[]){
  100.  
  101.  
  102.        System.out.println("-------- PostgreSQL JDBC Connection Testing ------------");
  103.  //     System.out.println(System.getProperty("user.dir"));
  104.  
  105.             try
  106.                   {
  107.                 System.out.println("hi");
  108.                     PropertyResourceBundle pBundle = null;
  109.                     //System.out.println("h32i");
  110.                       pBundle = new PropertyResourceBundle(new FileInputStream("D:/Bansari_Trainee/bansari_assign/Assign 2/Assign 2.1/assign2.1/src/assign21/DataProperty.properties"));
  111.                      //System.out.println("h32i");
  112.                      System.out.print(pBundle);
  113.                     String databaseInfo =  (pBundle.handleGetObject("POSTGRE")).toString();
  114.  
  115.                       if (!databaseInfo.equals(null))
  116.                       {
  117.                               WithPropertyFile dbConnect = new WithPropertyFile(pBundle.handleGetObject("POSTGRE").toString());
  118.                             dbConnect.open();
  119.  
  120.                               //dbConnect.close();
  121.                             System.out.println("Database Connection is Established From Connection Class...");
  122.                     }
  123.                       else
  124.                               System.out.println("\tNo such database found in properties file");
  125.  
  126.             }
  127.             catch(Exception e){
  128.             e.printStackTrace();}
  129.       }
  130.  
  131. }
  132.  
I m facing this runtime errorr::

java.lang.NullPointerException
java.util.PropertyResourceBundle@3e25a5
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
/src/assign21/DataProperty.properties
at assign21.WithPropertyFile.open(WithPropertyFile.ja va:67)

at assign21.DBConnection.main(WithPropertyFile.java:1 18)

This is my proprty file::

POSTGRE org.postgresql.Driver jdbc:postgresql:postgres postgres root4site



Please help as early as possible.
Jul 24 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.