Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006

    Unanswered: URGENT Java/SQLJ Help

    This is for my final exam that is due tomorrow. I've been trying everything & I just can't get it to work & my brain is turning to mush at this point. Please let me know if anyone can help...

    We need to generate data for a table based on what is in our host variables & the number of rows is determined by the user. So the idea is that we only store a few names & we can randomly pick combinations of first & last to insert into the database up to the number the user entered (dups are OK).

    So here is the basic code I have... If it stays like this is will just do Scott Jones, Mike Smith & Sally Miller. Then it will have an array out of bounds exception if the user entered anything more than 3. So I know I need to incorporate a random number generation to get different combinations, but I tried sticking the code everywhere & it wouldn't compile. PLEASE HELP!

    String[] fname = new String[] { "Scott", "Mike", "Sally"};
    String[] lname = new String[] { "Jones", "Smith", "Miller"};

    try { for (int i=0; i<intnum; i++)
    { #sql {INSERT INTO users VALUES
    (:(fname[i]), :(lname[i]))};
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2005
    Baltimore, MD
    What was your compiler error? Have you defined your variable intnum?

    try { 
       for (int i=0; i<intnum; i++) { 
          #sql { 
                   INSERT INTO users VALUES
                   (:(fname[i]), :(lname[i]))
    I've never used sqlj before...try commenting out the #sql block to see if you can compile. If you're sure you have the correct syntax, than maybe you have your java environment set up incorrectly?

Posting Permissions

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