Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Table Problem, or Code Problem?

 
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I'm new in this Forum, and I have a problem I don't quite understand...

You see I want to output a specific list of rows via a JTable, but the problem is It does not shows up..

P.S I want to put an image but don't know how.

Below is the full code

please look at
Function TFrame()
and Function FillTable()
















P.P.S I want to know what happens why there is no output, and is my way of coding bad?
If you have any suggestions, comments, violent reaction to help me improve my way of layouting codes and algorithm you can tell me.

 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to say, that's a whole ton of code to write before you find out that it doesn't work. If you're having problems with a JTable I would suggest writing a simple piece of code which demonstrates to you that you can use a JTable successfully. So: just a JTable, no other GUI stuff. And no database stuff, just something which hard-codes a couple of rows of the table. Once you have that working then you can expand on the simple code by adding in all the other features you need.

By the way "it doesn't show up" is sort of ambiguous; we can't tell whether the JTable isn't visible on the screen, or whether it is visible but contains no visible rows.
 
Paul Clapham
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And, welcome to the Ranch!
 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i'm trying to code a Project System (for practice)

> The JTable is visible on the screen but is only white, even with setting the DefaultTable Model
> Then I tried to put a View button that also does the same function of getting values via MetaData and storing them (so that I can repaint and see if something happens)

Is it my Table Declaration, or just the Output Algo?
 
Paul Clapham
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jobert John wrote:Is it my Table Declaration, or just the Output Algo?



No idea. As I said, there's way too much code there to debug. It might be a problem with your SQL, but there's at least 4 SQL queries in there that I could find. Maybe they return no data, or maybe they throw exceptions (your code ignores exceptions so you'd never know that -- don't ignore exceptions). So like I said, temporarily replace all of that SQL stuff with hard-coded data to see if your code which fills the JTables is right.
 
Bartender
Posts: 2899
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jobert, Welcome to code ranch.

I removed the part of your code into a small standalone program and it works fine:




Maybe its not your table code thats the issue ?
 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jobert John wrote:Is it my Table Declaration, or just the Output Algo?



No idea. As I said, there's way too much code there to debug. It might be a problem with your SQL, but there's at least 4 SQL queries in there that I could find. Maybe they return no data, or maybe they throw exceptions (your code ignores exceptions so you'd never know that -- don't ignore exceptions). So like I said, temporarily replace all of that SQL stuff with hard-coded data to see if your code which fills the JTables is right.




Ah right lemme Put flags to monitor process
 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So This might be because of the Query...

Joins are really confusing, Finding hard time in implementing it :'(
 
salvin francis
Bartender
Posts: 2899
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Are you sure there is a "teachers" table or a "teacher" table ?
Your initial query was: SELECT teacher_id FROM teacher WHERE teacher_id = ?

Never leave your catch block empty.

 
Marshal
Posts: 74371
334
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch again.

Another thing not to do is to use absolute positioning. Don't use a null for your Layout and don't specify the exact positions of the components. Let the Layout work that out for you.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jobert John wrote:So This might be because of the Query...

Joins are really confusing, Finding hard time in implementing it :'(



Then you ought to be sorting that part out as a separate piece of code, completely detached from the GUI.
Indeed, you shouldn't even be touching the Java side until you have a query ready to go, which involves just MySQL and whatever SQL editor you prefer.
Once you are certain you have the query correct, then create the code to return the data you want.
 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:

Jobert John wrote:So This might be because of the Query...

Joins are really confusing, Finding hard time in implementing it :'(



Then you ought to be sorting that part out as a separate piece of code, completely detached from the GUI.
Indeed, you shouldn't even be touching the Java side until you have a query ready to go, which involves just MySQL and whatever SQL editor you prefer.
Once you are certain you have the query correct, then create the code to return the data you want.



Actually I hva a seperate code for testing out Query output possibilities, and it is working.

The things is, nothing appears in the table that's all
even put a a flag to check if it process up to the algo of the inserting of values from sql to object.
 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:

Are you sure there is a "teachers" table or a "teacher" table ?
Your initial query was: SELECT teacher_id FROM teacher WHERE teacher_id = ?

Never leave your catch block empty.



Yes there is a  Teacher's table, and it is joined with schedule table.

But currently I tried using SELECT * from teachers, and still blank Jtable  
 
salvin francis
Bartender
Posts: 2899
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jobert John wrote:But currently I tried using SELECT * from teachers, and still blank Jtable  



A couple of things:
1. Did you try running all queries directly in the database as previously suggested by Dave Tolls ?
2. Did you try by writing a logger for exception in the empty catch block as previously suggested by me ?
 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:

Jobert John wrote:But currently I tried using SELECT * from teachers, and still blank Jtable  



A couple of things:
1. Did you try running all queries directly in the database as previously suggested by Dave Tolls ?
2. Did you try by writing a logger for exception in the empty catch block as previously suggested by me ?





Tried to use Stack Trace and this is what happened
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2497)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2455)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
at Scheduling.Schedlog.FillTable(Schedlog.java:357)
at Scheduling.Schedlog.Tframe(Schedlog.java:306)
at Scheduling.Schedlog$1.actionPerformed(Schedlog.java:80)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


I can't think of the problem here..

Firstly at ? when I put subject.teacher_id = 3000
It works, The table shows up

BUT!

When i now change it to subject.teacher_id = ?
That errors comes up...


And this is what the code looks like for that process


Please explain why, and what is happening that results of this error
 
Paul Clapham
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This ignores the fact that "prepare" is a PreparedStatement for which you have provided values for the parameter, and instead tries to execute "Query" as an SQL query. But "Query" has a question mark in it and is hence not valid SQL. As the error message says. So just execute the PreparedStatement:



One other thing. Please don't use variable names starting with a capital letter. It's an almost universal standard in Java to start variable names with a lower-case letter. That way Java programmers won't be misled and confused when they read your code.

 
Jobert John
Greenhorn
Posts: 12
Eclipse IDE MySQL Database C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,
now I quite understood Preparedstatement more!

and thank you for that reminder, I really need to study and study.

Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic