Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why is the column data not displaying?

 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't know whether to post this here or on JDBC. I thought I would start here, since I am still a beginner... This is my Java final project and I am desperate. I don't understand why the table and column data are not displaying. Is it a JDBC issue? Or am I adding them wrong?
This is the code:
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jade
Are you sure your getting a result back? Thrown in a System.out.println in your while loop to make sure you actaully get into it - so you know your getting data.
I didn't go through it in real detail but as a start try adding the lists to the panels after they've been created and then add the panels to the frame - that way you dont have to worry about revalidating or anything like that.
are you getting any errors?
If that doesn't work let me know and I'l check it our further and test it myself
Also, it is more of a JDBC issue so I'll move it there - unles sit turns out to be a swing issue then we can always move it again
[ February 24, 2002: Message edited by: Dave Vick ]
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think I am getting data back from the database. There were originally System.out.println() statements in the loop. I adapted it from the code my teacher gave us. His had print commands in it; I changed it when I adapted it for the GUI. Anyway, when I first ran the program nothing printed to the console. So that would lead me to believe that I am not getting the data. But it seems to be connecting to the database, since no exception is thrown.
No, I am not getting any errors. It compiles, but the text doesn't display. Except the headings "tables" and "columns", which I added. Those display, but nothing else does.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jade
I ran it here on a database I've got and I did get output. This leads me to believe that you might have a problem with the DSN you have set up.
The other thing, and dnt take this the wrong way, are there any tables in the database? I only ask because I've done it
Make sure the DB name is correct in the DSN and that the DSN points to the correct place.
One other thing I noticed, in your step number 3, where you loop through the table names you use the getString method to get the table name from the result set and send it to the giveTableDetails method then use it again to add it to the list - you're going to get an error here becasue you can only access the value once - if you go back and try to read it again you'll get an exception. Just read it once and assign it to a string varaible:

good luck

Dave
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the DSN and it looks like it is set up correctly and points to the database name that we were given in class.
I don't know whether there are tables in the database. I was assuming there were...My Java teacher gave us the database to connect to. But when I first tried it, using the program he gave us, I got an error saying that one of the tables I was trying to retrieve didn't exist. But then when I changed the code I stopped getting this error, so I don't know.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the database? Do you have a copy of it on oyur machine? Or are you connecting over the internet to it? What type of database is it by the way? Access, mySQL, etc...
If it is one your machine locally just open it and see if any tables come up in it. If it is over the wire then maybe it got corrupted and the tables are gone.
I assume it is a database your teacher created and you downloaded so you should have it on your machine.

Dave
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The database was supplied to us in class. It is an MS-Access database (SQL2000.mdb). We copied it from a diskette and I installed it on my home computer. I set up the ODBC in control panel the way we went over in class. I set up both Access and ODBC to point to the Java Class DSN, which is what we were supposed to do.
When I open the database in Access I see the headings (tables, queries, etc.) but I don't see anything listed under them. I am very confused.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you open the database click on the tables tab. If no tables show up in the area underneath the tabs then there are no tables in the database.
If you dont have any tables then just click create and create a new one, you dont even have to add any columns or data to it to see if your code works now - just add the table then save it and run your code. Make sure you close the table or you'll get an access error.
Give that a shot then you'll at least know your code works and you can get the data from your teacher later.
hope that does it for you - if you need more help let me know
Dave
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is working! Thank you so much.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure, glad to have been of help.
Now you just have to get the database from your teacher
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He just sent it to me.
Some other error came up. When I tried to change the name of the table I got a whole string of SQL exception errors. Then the computer crashed, with a fatal exception error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic