- Joined
- Nov 13, 2006
- Messages
- 15,688 (2.32/day)
- Location
- Mid-Atlantic
System Name | Desktop |
---|---|
Processor | i5 13600KF |
Motherboard | AsRock B760M Steel Legend Wifi |
Cooling | Noctua NH-U9S |
Memory | 4x 16 Gb Gskill S5 DDR5 @6000 |
Video Card(s) | Gigabyte Gaming OC 6750 XT 12GB |
Storage | WD_BLACK 4TB SN850x |
Display(s) | Gigabye M32U |
Case | Corsair Carbide 400C |
Audio Device(s) | On Board |
Power Supply | EVGA Supernova 650 P2 |
Mouse | MX Master 3s |
Keyboard | Logitech G915 Wireless Clicky |
Software | Fedora KDE Spin |
I am struggling to figure this out. I currently have a working method that populates a 2d array using a text file with 10 rows and 6 columns.
that is pretty straight forward as it uses the Scanner class to read through the text file. now i want to do the same thing but using a database table.
this is what i have so far. i keep running into: java.sql.SQLException: Column Index out of range, 0 < 1.
any insight would be helpful! apparently to do this properly i need to create a List. i am lost.
Code:
g_testdata = new double[G_TESTEXAMPLES][G_ATTRIBUTES+1];
File inTestFile = new File("testdata.dat"); //open test data file
Scanner inputTestFile = new Scanner(inTestFile);
for (int i=0; i < G_TESTEXAMPLES; i++)
{
for (int j=0; j < G_ATTRIBUTES+1; j++) // populate the test data array
{
g_testdata[i][j] = inputTestFile.nextDouble();
}
}
if (inputTestFile !=null) inputTestFile.close();
that is pretty straight forward as it uses the Scanner class to read through the text file. now i want to do the same thing but using a database table.
this is what i have so far. i keep running into: java.sql.SQLException: Column Index out of range, 0 < 1.
Code:
g_trainingdata = new double[G_TRAININGEXAMPLES][G_ATTRIBUTES+1];
try {
String connURL = "jdbc:mysql://{sanitized}";
String urlPass = "{sanitized}";
String urlUser = "{sanitized}";
// output user input for historical record
String query = "select squarefeet,bedrooms,bathrooms,lotsize,garage,current_price from pricePredictor.testdata";
Connection conn = DriverManager.getConnection(connURL,urlPass,urlUser);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
//retrieve number of columns and rows
int numRows, numCols;
if(!rs.next()){
return;
}
rs.last();
numRows = rs.getRow();
numCols = rs.getMetaData().getColumnCount();
System.out.println(numRows + " " + numCols); //for debugging purposes
rs.first();
//populate array using a for loop
for (int i=0; i < numRows; i++)
{
for (int j=0; j < numCols; j++)
{
g_trainingdata[i][j] = rs.getDouble(i); // populate the training data array
}
}
}//end of try
catch (SQLException e) {
System.out.println(e);
}
any insight would be helpful! apparently to do this properly i need to create a List. i am lost.
Last edited: