Results 1 to 3 of 3
Thread: Unknown error in Jtable...
- 02-23-2010, 05:32 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 9
- Rep Power
- 0
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);
}
}
- 02-23-2010, 05:33 AM #2
Member
- Join Date
- Feb 2010
- Posts
- 9
- Rep Power
- 0
sorry for not tagging..thought I did it correct..
-
Similar Threads
-
Adding unknown subclass
By happy_hippie in forum AWT / SwingReplies: 5Last Post: 09-03-2009, 01:39 PM -
Unknown design pattern
By Steve11235 in forum Advanced JavaReplies: 4Last Post: 07-02-2009, 12:40 PM -
Unknown problem
By sanchir0805 in forum New To JavaReplies: 4Last Post: 03-20-2009, 03:56 AM -
Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)"
By lavanya82 in forum JavaServer Pages (JSP) and JSTLReplies: 9Last Post: 02-20-2009, 07:22 AM -
java.net.MalformedURLException: unknown protocol: ntp
By Nicholas Jordan in forum NetworkingReplies: 6Last Post: 12-24-2008, 03:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks