hello
Is this String from my properties sheet able to become a prepared Statement. is the syntax compatable?

[b]if the string from properties is i=0 for the array [/b]
private boolean createTables(Connection conn) {
        for (int i = 0; i < schoolofdbTables.length; i++) {
            boolean bCreatedTables = false;
            PreparedStatement ps = null;
            try {
                ps = (PreparedStatement) conn.prepareStatement(
                        ModelUtils.getResource(schoolofdbTables[i]));
                ps.executeQuery();
                bCreatedTables = true;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
        return bCreatedTables;
    }
strCreateInstructorTable = \
CREATE TABLE instructor \
( \
instr_uid CHAR(11),\
instr_password CHAR(11),\
instr_lname CHAR(20),\
instr_mname CHAR(20),\
instr_fname CHAR(20),\
instr_gender CHAR(1),\
instr_start_date DATE,\
instr_end_date DATE,\
instr_age INT(3),\
instr_address CHAR(20),\
instr_state CHAR(2),\
instr_zip INT(5),\
instr_area_code INT(3),\
instr_phone INT(11),\
instr_location CHAR (11),\
instr_rate INT(4),\
instr_pay_rate INT(4),\
book_num INT(6),\
PRIMARY KEY(instr_uid) \
)\
INSERT INTO instructor \
(instr_uid,\instr_fname,\instr_password) VALUES ('ij','Johanne','i') \
INSERT INTO instructor \
(instr_uid,\instr_fname,\instr_password) VALUES ('im','Mozart','i')
the key:  strCreateAdminTable
Exception in thread "main" java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key  strCreateAdminTable
        at java.util.ResourceBundle.getObject(ResourceBundle.java:384)
        at java.util.ResourceBundle.getString(ResourceBundle.java:344)
        at model.ModelUtils.getResource(ModelUtils.java:48)
        at model.dao.ConnectDerbyDAO.createTables(ConnectDerbyDAO.java:179)

Thanks

Recommended Answers

All 6 Replies

check the name of the property against the name you're calling it as.

I copied the wrong String as an example. This is actually the first table to be created in the db.

#derby create table
strCreateAdminTable=DROP TABLE IF EXISTS admin \
CREATE TABLE admin \
( \
admin_uid CHAR(11),\
admin_password CHAR(11),\
admin_lname CHAR(20),\
admin_mname CHAR(20),\
admin_fname CHAR(20),\
admin_gender CHAR(1),\
admin_age INT(2),\
admin_start_date DATE,\
admin_end_date DATE,\
admin_address CHAR(20),\
admin_state CHAR(2),\
admin_zip INT(5),\
admin_area_code INT(3),\
admin_phone INT(11),\
admin_pay_rate INT(4),\
PRIMARY KEY(admin_uid)\
)\
INSERT INTO admin (admin_uid,admin_fname,admin_password) VALUES ('ag','Garth','a') \
INSERT INTO admin (admin_uid,admin_fname,admin_password) VALUES ('aw','Wayne','a')

it may not be able to find the properties file. Make sure it's placed correctly in the root of the classpath (or deeper, depending on exactly how you call it, the location of a properties file for loading a ResourceBundle is determined like that for a classfile).

it may not be able to find the properties file. Make sure it's placed correctly in the root of the classpath (or deeper, depending on exactly how you call it, the location of a properties file for loading a ResourceBundle is determined like that for a classfile).

I am not sure exactly how to do that but I get the resources as so...

public class ModelUtils {
     private static ResourceBundle resources;

    public static final String RESOURCES
        = ModelUtils.class.getPackage().getName()
        + ".res.ModelResources";
    private static StudentDAO studentDAO;
    private static InstructorDAO instructorDAO;
    private static AdminDAO adminDAO;
    private static PayeeDAO payeeDAO;

    public static void log(Throwable x) {
        Logger.global.log(Level.SEVERE, x.getMessage(), x);
    }

    public static synchronized ResourceBundle getResources() {
        if (resources == null)
            try {
                resources = ResourceBundle.getBundle(RESOURCES);
            } catch (MissingResourceException x) {
                log(x);
                throw new InternalError(x.getMessage());
            }
        return resources;
    }

    public static String getResource(String key) {
        System.out.println("the key: "+key.valueOf(key));
        return getResources().getString(key);
    }

error:

resources in model.res.ModelResources.properties

Exception in thread "main" java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key  strCreateAdminTable
        at java.util.ResourceBundle.getObject(ResourceBundle.java:384)
        at java.util.ResourceBundle.getString(ResourceBundle.java:344)
        at model.ModelUtils.getResource(ModelUtils.java:48)
        at model.dao.ConnectDerbyDAO.createTables(ConnectDerbyDAO.java:179)
        at model.dao.ConnectDerbyDAO.createDatabase(ConnectDerbyDAO.java:168)
        at model.dao.ConnectDerbyDAO.<init>(ConnectDerbyDAO.java:91)
        at model.dao.ConnectDerbyDAO.<init>(ConnectDerbyDAO.java:80)
        at model.dao.DerbyDAOFactory.buildDB(DerbyDAOFactory.java:16)
        at view.Main.main(Main.java:33)

like I said, it can't find the properties file. Place it where it can be found and it should be picked up.
If you don't know how to do that, learn a bit about classpaths etc. as there's nothing anyone here will be able to do for you except repeating what I've already said over and over again.

like I said, it can't find the properties file. Place it where it can be found and it should be picked up.
If you don't know how to do that, learn a bit about classpaths etc. as there's nothing anyone here will be able to do for you except repeating what I've already said over and over again.

ok thanks for your time. stupid mistake on my part. I was confused on why it found any other 'key' but not that one.
I had a space in the string
resolved by:

ModelUtil.getResourc(schoolofdbTables[i].trim());

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.