I can not get data from Table cell  
Author Message
sahm





PostPosted: 2007-9-24 22:19:00 Top

java-programmer, I can not get data from Table cell Hi every one
I try to get String from cell in jTable
every time I try to get data from cell I only get null
and this is my code
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Class.forName("com.mysql.jdbc.Driver");
Connection con;
con = DriverManager.getConnection("jdbc:mysql://localhost/
uni","root","java");
Statement stat = con.createStatement();
ResultSet result;
result = stat.executeQuery("select max(no) from student_info_table");
result.next();
int mx, c;
mx = result.getInt(1);
mx = mx +1;


String inserting_Data = "insert into fee_part_table (feeNO, feeParts,
fee_1st_part) values(?, ?, ?)";
PreparedStatement ps = null;
ps = con.prepareStatement(inserting_Data);

ps.setInt(1, mx);
ps.setInt(2, c);

String st;
st = String.valueOf(jTable2.getValueAt(0, 0));

JOptionPane.showMessageDialog(this, st);

ps.setString(3, String.valueOf(jTable2.getValueAt(0, 0)));
ps.executeUpdate();
///////////////////////////////////////////////

 
sahm





PostPosted: 2007-9-24 22:22:00 Top

java-programmer >> I can not get data from Table cell I can not get data from Table cell


Hi every one
I try to get String from cell in jTable
every time I try to get data from cell I only get null
and this is my code
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Class.forName("com.mysql.jdbc.Driver");
Connection con;
con = DriverManager.getConnection("jdbc:mysql://localhost/
uni","root","java");
Statement stat = con.createStatement();
ResultSet result;
result = stat.executeQuery("select max(no) from student_info_table");
result.next();
int mx, c;
mx = result.getInt(1);
mx = mx +1;


String inserting_Data = "insert into fee_part_table (feeNO, feeParts,
fee_1st_part) values(?, ?, ?)";
PreparedStatement ps = null;
ps = con.prepareStatement(inserting_Data);

ps.setInt(1, mx);
ps.setInt(2, c);

String st;
st = String.valueOf(jTable2.getValueAt(0, 0));

JOptionPane.showMessageDialog(this, st);

ps.setString(3, String.valueOf(jTable2.getValueAt(0, 0)));
ps.executeUpdate();
///////////////////////////////////////////////

 
Roedy Green





PostPosted: 2007-9-24 22:39:00 Top

java-programmer >> I can not get data from Table cell On Mon, 24 Sep 2007 14:21:50 -0000, sahm <email***@***.com> wrote,
quoted or indirectly quoted someone who said :

>st = String.valueOf(jTable2.getValueAt(0, 0));

The code that holds the key to your problem is your declaration of
jTable2 and where you store values in jTable2. I don't see that in
your snippet.
See http://mindprod.com/jgloss/sscce.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
 
RedGrittyBrick





PostPosted: 2007-9-24 22:39:00 Top

java-programmer >> I can not get data from Table cell sahm wrote:
> I can not get data from Table cell
>

Multiposted.
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

 
 
Andrew Thompson





PostPosted: 2007-9-24 22:41:00 Top

java-programmer >> I can not get data from Table cell sahm wrote:
>I can not get data from Table cell
..
>I try to get String from cell in jTable

Unless you mean JTable, I do not know the class
you are referring to, and if you *are* referring to
JTable, please take care to use the correct
capitalisation.

>every time I try to get data from cell I only get null
>and this is my code
(snip snippets)

These are code snippets. They do not even compile here,
let alone display the problem. Perhaps if you prepared an
SSCCE* and copy/pasted the first 10-20 lines of the Exception
Stacktrace that occurs, you would have a better chance of
being helped.

* <http://www.physci.org/codes/sscce.html>

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1

 
 
Ingo R. Homann





PostPosted: 2007-9-24 22:55:00 Top

java-programmer >> I can not get data from Table cell Hi,

sahm wrote:
> Hi every one
> I try to get String from cell in jTable
> every time I try to get data from cell I only get null
> and this is my code
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> Class.forName("com.mysql.jdbc.Driver");
> Connection con;
> con = DriverManager.getConnection("jdbc:mysql://localhost/
> uni","root","java");
> Statement stat = con.createStatement();
> ResultSet result;
> result = stat.executeQuery("select max(no) from student_info_table");
> result.next();
> int mx, c;
> mx = result.getInt(1);
> mx = mx +1;

Are you sure, result.next() returns true?

What does it mean, you "get null"? result.getInt() will not return null.
Do you get a NullPointerException? If yes, *where* do you get it?

Ciao,
Ingo

 
 
Lew





PostPosted: 2007-9-25 5:37:00 Top

java-programmer >> I can not get data from Table cell sahm wrote:
>> I can not get data from Table cell
> ...
>> I try to get String from cell in jTable

Andrew Thompson wrote:
> Unless you mean JTable, I do not know the class
> you are referring to, and if you *are* referring to
> JTable, please take care to use the correct
> capitalisation.

sahm wrote:
>> every time I try to get data from cell I only get null
>> and this is my code

Andrew Thompson wrote:
> * <http://www.physci.org/codes/sscce.html>

sahm wrote:
>> Class.forName("com.mysql.jdbc.Driver");

You only need to load the class once, not every time you make a connection.

>> Connection con;
>> con = DriverManager.getConnection("jdbc:mysql://localhost/uni","root","java");

Why not
Connection con =
DriverManager.getConnection( "jdbc:mysql://localhost/uni", "root", "java" );
?

>> Statement stat = con.createStatement();
>> ResultSet result;
>> result = stat.executeQuery("select max(no) from student_info_table");

Why not
ResultSet result =
stat.executeQuery( "select max(no) from student_info_table" );
?

>> result.next();

Ingo R. Homann wrote:
> Are you sure, result.next() returns true?

>> int mx, c;
>> mx = result.getInt(1);
>> mx = mx +1;

You set mx to a value, then increment it separately instead of in one
statement, and you don't ever set a value for c.

>>
>> String inserting_Data = "insert into fee_part_table (feeNO, feeParts,
>> fee_1st_part) values(?, ?, ?)";
>> PreparedStatement ps = null;
>> ps = con.prepareStatement(inserting_Data);

Why initialize ps then immediately discard the initial value?

>> ps.setInt(1, mx);
>> ps.setInt(2, c);

c was never set.

>> String st;
>> st = String.valueOf(jTable2.getValueAt(0, 0));

Why not
String st = String.valueOf( jTable2.getValueAt(0, 0) );
?

>> JOptionPane.showMessageDialog(this, st);

Intermingling GUI and DB code like this is not good structure. You should
also be sure that GUI code runs on the Event Dispatch Thread (EDT) and that
the database code does not.

>> ps.setString(3, String.valueOf(jTable2.getValueAt(0, 0)));
>> ps.executeUpdate();

Roedy Green said:
> ... you posted this twice independently. This splits the discussion.
> Don't do this. See
<http://mindprod.com/jgloss/multiposting.html>

Andrew Thompson wrote:
> These are code snippets. They do not even compile here,
> let alone display the problem. Perhaps if you prepared an
> SSCCE* and copy/pasted the first 10-20 lines of the Exception
> Stacktrace that occurs, you would have a better chance of
> being helped.
>
> * <http://www.physci.org/codes/sscce.html>

--
Lew
 
 
apm35





PostPosted: 2007-9-25 15:24:00 Top

java-programmer >> I can not get data from Table cell On 24 Sep, 22:37, Lew <email***@***.com> wrote:
> Intermingling GUI and DB code like this is not good structure. You should
> also be sure that GUI code runs on the Event Dispatch Thread (EDT) and that
> the database code does not.

I'd put it a bit stronger than that. Intermingling GUI and DB code
like this means that the GUI may not work properly since GUI work must
be done in the EDT in order for swing to function properly. Also, when
in the EDT, non-GUI work must be shunted off to a different thread so
that the EDT is only doing GUI work.

-Andrew Marlow