Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Properties does have getProperty method

843859Aug 30 2006 — edited Sep 12 2006
I have this code but the Properties does have the method getProperty()
import java.io.*;
import java.sql.*;
import java.util.*;

public class TestCode {
    static final String PROPERTY_FILE="JDBC-ODBC Driver.properties";
    String driverName, url, user, password;
    
    /** Creates a new instance of TestCode */
    public void access() {
        try{
            /* Create an object of the Properties class and load properties. */
            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.
            /* Initialize and load a driver. */            
            Class.forName("driverName");
            /* Establish a connection with a database. */
            Connection con=DriverManager.getConnection(url,user,password);
            /* Create Statement object. */
            Statement stmt=con.createStatement();
            /* Executes a SQL query to retrieve a ResultSet. */
            ResultSet rs=stmt.executeQuery("SELECT * FROM Registered_Users_Information");
            /* Iterate through the ResultSet to display data. */
            while(rs.next()){
                System.out.println(rs.getString("UserName"));
                System.out.println(rs.getString("Password"));
            }
            con.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static void main(String args[]){
        TestCode t=new TestCode();
        t.access();
    }
    
}
Please show me the problem.
Thanks.
Nguyen_Tom
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2006
Added on Aug 30 2006
8 comments
196 views