Declaring Connection-Related Variables

Connection information is passed to the connection method by using the following connection variables: the connection URL, a user name, and the corresponding password.

Use the Java Source Editor of JDeveloper to edit the DataHandler.java class as follows:

  1. After the DataHandler constructor, on a new line, declare the three connection variables as follows:
    String jdbcUrl = null;
    String userid = null;
    String password = null; 
    

    These variables will be used in the application to contain values supplied by the user at login to authenticate the user and to create a connection to the database. The jdbcUrl variable is used to hold the URL of the database that you will connect to. The userid and password variables are used to authenticate the user and identify the schema to be used for the session.

    Note:

    The login variables have been set to null to secure the application. At this point in the guide, application login functionality is yet to be built into the application. Therefore, to test the application until login functionality is built in, you can set values in the login variables as follows:

    Set the jdbcUrl variable to the connect string for your database.

    String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORACLE";
    

    Set the variables userid and password to hr as follows:

    String userid = "hr";
    String password = "hr";
    

    Make sure you reset these to null as soon as you finish testing.

    For more information about security features and practices, refer to Oracle Database Security Guide and the vendor-specific documentation for your development environment.

  2. On a new line, declare a connection instance as follows:
    Connection conn;
    

    Your Java class should now contain the code as shown in the following code example.

    Declaring Connection Variables and the Connection Object

    package hr;
    import java.sql.Connection;
    import oracle.jdbc.pool.OracleDataSource;
     
    public class DataHandler {
        public DataHandler() {
        }
        String jdbcUrl = null;
        String userid = null;
        String password = null; 
        Connection conn;
    }