• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable-Getting Data out to db

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having great difficulty getting the data out of my JTable once it is populated and then the data is changed by the user. I extended DefaultTableModel for my tableModel then returned a ResultSet via SQLJ to populate the table. The data displays when I run the Applet and I have overridden isCellEditable making cells 1 to 8 editable. Structure of the table is as follows:
ID, Project, hrsMon hrsSun,total hrs
int, String, float, float, float, float, float, float, float, float
When I call getDataVector and try to display the data (for debug, what I really need to do is post changes to the db: oracle by the way) I get back null.
Code Snippet for accessing getDataVector:
private void saveData()
{
Vector newVector;
String newString[];// = new String[10];
String stupidString;
try
{
newVector = aModel.getDataVector();
newVector.trimToSize();
newString = new String[newVector.size()];
//just testing to see if I can show one element from the Vector. What
//I'll really do is pass the Vector to a SQLJ servlet then parse the data
//out and insert into the db.
stupidString = newString[1];
//newString[1] = (String)newVector.elementAt(2);
//newString = newVector.toString();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
newString = new String[10];
stupidString ="err";
}
JOptionPane.showMessageDialog(null,"Record = "+stupidString);
//return newString;
}
As you can see I tried a couple different ways of getting the data out of the Vector but have met with defeat.
Tried the tutorial using tables and this part seems to be assumed that we'd know how to do it.
Any help will be greatly appreciated.
Thanks
Stuart
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you aware that 'newVector.elementAt(2)' will return a vector conisting of more vectors? It will return all of row two. If you wanted to get, say, row two's column one, you'd use:

[ February 15, 2004: Message edited by: Peyton McCullough ]
 
Stuart Hoffman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I was not aware, thanks.
I changed that line as follows:
try
{
newVector = bottomPanel.getAModel().getDataVector();
newVector.trimToSize();
newString = new String[newVector.size()];
stupidString = newString[1];
//newString[1] = (String)newVector.elementAt(2);
//NEW line below
newString[1] = (String)(((Vector)newVector.elementAt(1)).elementAt(0));
//newString = newVector.toString();
}
and I get the following error:
--
java.lang.ClassCastException: java.math.BigDecimal
void SwingTimeSheet.saveData()
SwingTimeSheet.java:193
--
line 193 is the change in the code. The column
I'm getting back would be an int so what did I do wrong?
 
Peyton McCullough
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the datatypes in the columns of your table? This may shed some light on the problem...
 
Stuart Hoffman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The column types are
Integer, Varchar2(30),float,float,float,float,float,float,float,float
0 1 2 3 4 5 6 7 8 9
Cols 0 and 9 are not editable.
cols 2-8 will be summed into 9.
Thanks
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw in this other post where you were using BigDecimal for the sum column... if you have changed this to Float, doublecheck and make sure you have changed this in all the places it could possibly be... this is the only place I could think you might be getting your ClassCastException from.
 
Stuart Hoffman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,
That was only my thrashing , trying several different datatypes in order to see what worked. Notice that long sum calculation was commented out?
That was the only way I could get it to compile.
Any ideas?
Can't can it and start over though
 
reply
    Bookmark Topic Watch Topic
  • New Topic