Link to home
Start Free TrialLog in
Avatar of Titanfan21
Titanfan21

asked on

Displaying the results of a MySQL Query in a NetBeans JTable

How would I go about displaying the results of a simple MySQL select statement in a JTable component in NetBeans 6.0?

Something like this:

select ID, FIRST, LAST from table where variable = 'Y';

Any help would be appreciated!

Mark
ASKER CERTIFIED SOLUTION
Avatar of Nellios
Nellios
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Titanfan21
Titanfan21

ASKER

Wow, very cool.

What I did was go into the properties of the empty JTable and clicked on 'Customize Code.'  Then in the second dropbox on the left I chose 'custom property', where I pasted the stuff in there over what was already there.  That's what I'm supposed to do, right?
Here were a couple other quick questions I had:

1) You start out the code with 'Object', but what was originally there said 'new Object.'  Should I do it like that, or just leave it as Object.

2) At the end of the line that reads:
String Query = "select ID, FIRST, LAST from table where variable = 'Y";;
You put two semicolons.  Should there be just one, or two?

3) When I try to run the project to test it out, it says:
Class "myproject.TableTest" does not have a main method.
How would I fix that so it will run?

Thanks so much for your help!

Mark

Also, it won't let me run the program as it says
Ok.  I've been fooling around with this a little bit and am getting one error when I try to run it:

(File Path Here).java:275: array dimension missing
            new Object[][] Data = null;
1 error
BUILD FAILED (total time: 0 seconds)

Any idea what this means or how to fix it?

If I look in the source, there looks to be a few other errors as well.

cannot find symbol
symbol : variable my JDBCConnection
symbol : method createStatement()
symbol : variable netSize

operator > cannot be implied to netSize, int

cannot find symbol
variable : Data
symbol : constructor DefaultTableModel(Data,java.lang.String[])
variable: mytable

Not sure if those will matter once the main error that it gives when I try to run it gets fixed.

Thanks so much!

Mark
Sorry for the delay:

1) Left Click - > Fix Imports should decrease the errors.
2) My code sample assumes that you have basic experience in using mysql JDBC from java. This means
that you still have to initialize the driver and connect to the database yourself.
"myJDBCConnection" needs to be a java.sql.Connection Object ready to create statements.
3) netSize is a typo, should be size.
4) You need to create a main method. If netbeans hasn't already done that for you (which should in Project creation) then you need to choose which is your starter class and add the a main method (Java Basics).

Thanks!  I did all of that, but I'm still getting the primary error when I try to run it.

(File Path Here).java:275: array dimension missing
            new Object[][] Data = null;
1 error
BUILD FAILED (total time: 0 seconds)

Do you know why it's doing that?

Thanks!

Mark
As it says you are trying to construct an array ( new Obect[][] ) with no dimension.
I feel that you wanted to type something like Obect[][] Data = null;
Forced accept.

Computer101
EE Admin