Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL data into table

 
Rafal Szulejko
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I've got a problem while importing data from MySQL into a table. Could you tell me where it is?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like you're posing a riddle :-)

Why don't you tell us what you expected to happen, and what actually happened.
 
Rafal Szulejko
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha, sorry :p
I want it to get all fields from MySQL table and put them into table, every time I change something I have different different exception, ArrayIndexOutOfBoundsException this time. I'm almost sure I created all tables properly, I have no idea what to change.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you're not going to tell us the exact problem, and the details of the exceptions? That will make it harder for us to help you.
 
Rafal Szulejko
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm really sorry, I just see this a bit different from you and I have problem with seeing it as you do.
An exception occurs when I try to assign data from ResultSet into table (line 18 in posted code).
This function has to load all data from table and put them into proper cells of table ( String[][] data ). I think there is something wrong with the loop (15-21), but it's a bit complicated and I don't know what to change.
 
Paul Clapham
Sheriff
Posts: 21566
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually we don't see anything. You're the one who can see things. You got a stack trace, didn't you? So what is preventing you from showing it to us?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one thing that particularly stands out, actually. The two loops in your code should be inverted. Your outer loop goes over all columns, and your inner loop goes over the rows in the resultset. That means that after processing the first column, your resultset is already at the end. The solution is simple - make the outer loop go over individual rows in the resultset, and inside it loop over individual columns.

I would also suggest not to count the rows beforehand. Use a List collection (probably the ArrayList implementation) to store your results instead (in your case, it would be a list of string arrays, ie. List<String[]>). The list grows as needed, you don't need to know the size of the list beforehand.
 
Rafal Szulejko
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys, I thought that posting full stack trace was discouraged by sscce. Don't kill me, but I won't post it now, let me explain :p
Martin, thanks for suggesting of inverting the loops, the program works hardly, but works. I'll definitely play with the collections after finishing the program my way, I haven't learned them yet.
I'll try to continue the program myself, and I'll post everything here when I'll be stuck again - moderators, don't close the thread please.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic