Results 1 to 3 of 3

Thread: Property File

  1. #1
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    Default Property File

    I have this code but it have the problem about load file. Please help me load the file I need("ODBC-JDBC Driver.properties")
    Java Code:
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class TestCode {
    static final String PROPERTY_FILE="ODBC-JDBC Driver.properties";
    String driverName, url, user, password;
    public void Test() {
    try{
    Properties prop=new Properties();
    prop.load(new FileInputStream(PROPERTY_FILE));
    driverName=prop.getProperty("driver"); // Retrieve driver information.
    url=prop.getProperty("url"); // Retrieve JDBC URL.
    user=prop.getProperty("user"); // Retrieve user name.
    password=prop.getProperty("password"); // Retrieve password.
    Class.forName("driverName");
    Connection con=DriverManager.getConnection(url,user,password);
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("SELECT * FROM Registered_Users_Information");
    while(rs.next()){
    System.out.println(rs.getString("UserName"));
    System.out.println(rs.getString("Password"));
    }
    }catch(Exception ex){
    ex.printStackTrace();
    }
    }
    public static void main(String args[]){
    TestCode t=new TestCode();
    t.Test();
    }
    }

    Thanks.

  2. #2
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

    Default

    Put the file in the directory indicated by user.dir
    ( System.getProperty("user.dir"); )
    or specify the entire path.

  3. #3
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    8

    Default

    Class.forName("driverName");
    should be
    Class.forName(driverName);
    without the quotes.

Similar Threads

  1. How to store property file into key value pair
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-05-2008, 11:16 AM
  2. Initializing property object from a file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-29-2007, 05:55 PM
  3. property for radio buttons
    By swapnanair in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-03-2007, 09:39 AM
  4. where is the system.property
    By osval in forum Advanced Java
    Replies: 2
    Last Post: 08-06-2007, 04:54 AM
  5. log4j property file in my application
    By Peter in forum Advanced Java
    Replies: 3
    Last Post: 06-14-2007, 04:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •