Results 1 to 3 of 3
  1. #1
    blu_fox88 is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default Unknown error in Jtable...

    Im not sure where the error is in the code but I believe it is correct although I still get:
    Error: java.lang.ArrayIndexOutOfBoundsException: 1
    ......
    How do I fix this???Also how can I put a loop in the table model so that I can display multiple results...???
    here is the code:

    try {
    String CurrencyS = (String)jComboBox7.getSelectedItem();
    String YearS = (String)jComboBox9.getSelectedItem();
    String MonthS = (String)jComboBox8.getSelectedItem();
    String DayS = (String)jComboBox10.getSelectedItem();
    String Carbon = "";
    String [] CurrencyP = {};
    String [] YearP = {};
    String [] MonthP = {};
    String [] DayP = {};
    int i = 1;
    int j = 1;
    if (CurrencyS.equals("MYR")) Carbon = "USD/MYR";
    else if (CurrencyS.equals("EUR")) Carbon = "USD/EUR";
    else if (CurrencyS.equals("GBP")) Carbon = "USD/GBP";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    // set this to a MS Access DB you have on your machine
    String filename = "E:/Database11.mdb";
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
    // now we can get the connection from the DriverManager
    Connection con = DriverManager.getConnection( database ,"","");
    Statement s = con.createStatement();
    if (MonthS.equals("All"))
    {
    s.execute("select * from Rop where Year = " + YearS + " and Day = " + DayS); // select the data from the table
    ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
    while((rs!=null) && (rs.next()))
    {
    if (rs.next())
    {
    if (CurrencyS.equals("MYR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(5);
    }
    else if (CurrencyS.equals("EUR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(6);
    }
    else if (CurrencyS.equals("GBP"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(7);
    }
    i = i + 1;
    }
    }
    }
    else if (DayS.equals("All"))
    {
    s.execute("select * from Rop where Year = " + YearS + " and Month = " + MonthS); // select the data from the table
    ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
    while((rs!=null) && (rs.next()))
    {
    if (rs.next())
    {
    if (CurrencyS.equals("MYR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(5);
    }
    else if (CurrencyS.equals("EUR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(6);
    }
    else if (CurrencyS.equals("GBP"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(7);
    }
    i = i + 1;
    }
    }
    }
    else if ((MonthS.equals("All")&&(DayS.equals("All"))))
    {
    s.execute("select * from Rop where Year = " + YearS); // select the data from the table
    ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
    while((rs!=null) && (rs.next()))
    {
    if (rs.next())
    {
    if (CurrencyS.equals("MYR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(5);
    }
    else if (CurrencyS.equals("EUR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(6);
    }
    else if (CurrencyS.equals("GBP"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(7);
    }
    i = i + 1;
    }
    }
    }
    else
    {
    s.execute("select * from Rop where Year = " + YearS + " and Day = " + DayS + " and Month = " + MonthS); // select the data from the table
    ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
    while((rs!=null) && (rs.next()))
    {
    if (rs.next())
    {
    if (CurrencyS.equals("MYR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(5);
    }
    else if (CurrencyS.equals("EUR"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(6);
    }
    else if (CurrencyS.equals("GBP"))
    {
    YearP[i] = rs.getString(2);
    MonthP[i] = rs.getString(3);
    DayP[i] = rs.getString(4);
    CurrencyP[i] = rs.getString(7);
    }
    i = i + 1;
    }
    }
    }


    jTable1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][]
    {
    {YearP[1], MonthP[1], DayP[1], CurrencyP[1]},
    {null, null, null, null}
    },
    new String []
    {
    "Year", "Month", "Day", Carbon
    }
    )
    {
    Class[] types = new Class []
    {
    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
    };

    @Override
    public Class getColumnClass(int columnIndex) {
    return types [columnIndex];
    }
    });

    {


    }
    s.execute("drop table Rop");
    s.close();
    con.close();

    }



    catch (Exception e) {
    System.out.println("Error: " + e);
    }

    }

  2. #2
    blu_fox88 is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default

    sorry for not tagging..thought I did it correct..

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by blu_fox88 View Post
    sorry for not tagging..thought I did it correct..
    You can still edit your post. If you need more help on code tags, please click on the link in my signature below.

Similar Threads

  1. Adding unknown subclass
    By happy_hippie in forum AWT / Swing
    Replies: 5
    Last Post: 09-03-2009, 02:39 PM
  2. Unknown design pattern
    By Steve11235 in forum Advanced Java
    Replies: 4
    Last Post: 07-02-2009, 01:40 PM
  3. Unknown problem
    By sanchir0805 in forum New To Java
    Replies: 4
    Last Post: 03-20-2009, 04:56 AM
  4. Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)"
    By lavanya82 in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 02-20-2009, 08:22 AM
  5. java.net.MalformedURLException: unknown protocol: ntp
    By Nicholas Jordan in forum Networking
    Replies: 6
    Last Post: 12-24-2008, 04:35 AM

Posting Permissions

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