5 Replies Latest reply: May 26, 2012 8:21 PM by 937555 RSS

    Constant Declaration in a file

    937555
      Below is my constant file where I have declared my constants and I am using these constants in a different class file by referencing as LnPDataConstants.VariableName (whatever I want to use) , as I am new to Java, my questions is whether the constants I have declared as static and final in this class file is right or not? You can figure this out by seeing the variable declaration I guess. Any suggestions will be appreciated.

      public class LnPDataConstants {
           
           
           // JDBC driver name and database URL
           public static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
           public static final String DB_URL = "jdbc:oracle:thin:@localhost:1521:ORCL";
           // Database credentials
           public static final String USER = "scott";
           public static final String PASS = "tiger";

      // These are used to create a statement, connection, preparedstatement
           public static Connection DB_CONNECTION = null;
           public static Statement STATEMENT = null;
           public static PreparedStatement PSTMT = null;

      // all the below variables has to be inserted in to database everytime.
           public static String CGUID_VALUE = null;
           public static String SGUID_VALUE = null;
           public static String PGUID_VALUE = null;
           public static String UID_VALUE = null;
           public static String SITEID_VALUE = null;
           public static String ALOC_VALUE = null;
           public static String ULOC_VALUE = null;
           public static String SLOC_VALUE = null;
           public static String PLOC_VALUE = null;
           public static String CLOC_VALUE = null;

           public static final String DATABASE_TABLE = "LnPData";

           public static final String CREATE_SQL = "CREATE TABLE " DATABASE_TABLE
           "(ID number(10,0), " +
           " CGUID VARCHAR(255), " +
           " PGUID VARCHAR(255), " +
           " SGUID VARCHAR(255), " +
           " USERID VARCHAR(255), " +
           " ULOC VARCHAR(255), " +
           " SLOC VARCHAR(255), " +
           " PLOC VARCHAR(255), " +
           " ALOC VARCHAR(255), " +
           " SITEID VARCHAR(255), " +
           " PRIMARY KEY ( ID ))";
           
           
           public static final String DROP_SQL = "DROP TABLE " +DATABASE_TABLE;

           public static final String SELECT_SQL = "SELECT * FROM " DATABASE_TABLE " WHERE ID = ?";
           
           public static final String INSERT_SQL = "INSERT into " DATABASE_TABLE "(ID, CGUID, PGUID, SGUID, USERID, ULOC, SLOC, PLOC, ALOC, SITEID) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
           
           // Update and Insert both as we need to insert a lot of data and also update it.
           public static final String UPSERT_SQL = "MERGE INTO " DATABASE_TABLE " USING ( SELECT ? AS ID, " + // We will maybe add this record
      " ? AS CGUID, " +
      " ? AS PGUID, " +
      " ? AS SGUID, "+
           " ? AS USERID, "+
           " ? AS ULOC, "+
           " ? AS SLOC, "+
           " ? AS PLOC, "+
           " ? AS ALOC, "+
           " ? AS SITEID, "+
           " FROM dual ) maybe "+
           // Checking whether ID got matched, if matched then we will update the database table (ULOC, SLOC, PLOC, ALOC)
      " ON (maybe.ID = "+DATABASE_TABLE+".ID) "+
      " WHEN MATCHED THEN "+
                // We only need update the fields that might have changed
      " UPDATE SET " DATABASE_TABLE ".ULOC = maybe.ULOC, " DATABASE_TABLE ".SLOC = maybe.SLOC, " DATABASE_TABLE ".PLOC = maybe.PLOC, " DATABASE_TABLE ".ALOC = maybe.ALOC "+
           // If not matched then we will Insert new records in the database.
      " WHEN NOT MATCHED THEN "+
      // Insert new record
      " INSERT VALUES (maybe.ID, maybe.CGUID, maybe.PGUID, maybe.SGUID, maybe.USERID, maybe.ULOC, maybe.SLOC, maybe.PLOC, maybe.ALOC, maybe.SITEID)";
           

      // These are the constant which wont be changing.
           public static final int CGUID_ID = 347;
           public static final int SGUID_ID = 248;
           public static final int PGUID_ID = 202;
           public static final int UID_ID = 12;
           public static final int SITE_ID = 20000;
           public static final int ALOC_ID = 331;
           public static final int ULOC_ID = 333;
           public static final int SLOC_ID = 330;
           public static final int PLOC_ID = 332;
           public static final int CLOC_ID = 20001;


      }