This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable" Watch "Jtable" New topic
Author

Jtable

kamiya sei
Greenhorn

Joined: Dec 12, 2012
Posts: 25
HI all, I have a file called StudentFrame when I click "Submit " button to show all data from database ,but it doesn't show although connected database successfully.


public class StudentFrame extends javax.swing.JFrame {

/**
* Creates new form StudentFrame
*/
public StudentFrame() {
initComponents();

header=new Vector();

header.add("name");
header.add("mark");
header.add("grade");
header.add("class");
}

public ArrayList<Student> getAllRows() {

try {
Connection con = ConnectData.getConnection();

ArrayList<Student> lst = new ArrayList<>();
String sql = " select * from StudentInfo";
PreparedStatement pr;

pr = con.prepareStatement(sql);
ResultSet rs = pr.executeQuery();

Student std = new Student();

while (rs.next()) {
rs.getString("name");
rs.getFloat("mark");
rs.getString("grade");
rs.getString("class");
lst.add(std);
}
return lst;


} catch (SQLException ex) {
return null;
}


}

public boolean ExcuteStudent(String name, String UpdateField, String UpdateValue) {
try {
Connection con = ConnectData.getConnection();
// String sql="update StudentInfo set " +UpdateField+"=?"+"where name = ?";
String sql = "update StudentInfo set";

sql += UpdateField + "=? ";
sql += "where name=?";

PreparedStatement pr = con.prepareStatement(sql);
pr.setString(1, UpdateValue);
pr.setString(2, name);

return pr.executeUpdate() > 0;
} catch (SQLException ex) {
return false;
}

}
private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {

data =new Vector();
tablemodel=new DefaultTableModel(data, header);
tablemodel.fireTableDataChanged();
jTable1.setModel(tablemodel);
btnSubmit.setEnabled(true);
getAllRows();

}

private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {
:
ExcuteStudent(null, null, null);
}
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Hi kamiya,
We have several forums here for technical discussions. This topic is related to Swing and we have a forum just for that: Swing.
I will be moving this post to that forum. Feel free to continue your discussions there.

Note that this forum is 'Meaningless' and your chances of getting a meaningful response to a technical problem is quite low
So, CarefullyChooseOneForum before you post.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Hi kamiya,
In your code, in your try-catch block, you are just returning null and not examining the exception at all. Note that, if there are issues related to database access, a SQLException will be thrown. So, I would suggest you to first do a printStackTrace in the catch block to see if that is the case.

Also, please UseCodeTags (<--link) when posting code.
kamiya sei
Greenhorn

Joined: Dec 12, 2012
Posts: 25
Ranganathan Kaliyur Mannar wrote:Hi kamiya,
We have several forums here for technical discussions. This topic is related to Swing and we have a forum just for that: Swing.
I will be moving this post to that forum. Feel free to continue your discussions there.

Note that this forum is 'Meaningless' and your chances of getting a meaningful response to a technical problem is quite low
So, CarefullyChooseOneForum before you post.



Thanks . Ranganathan Kaliyur Mannar
kamiya sei
Greenhorn

Joined: Dec 12, 2012
Posts: 25
Ranganathan Kaliyur Mannar wrote:Hi kamiya,
In your code, in your try-catch block, you are just returning null and not examining the exception at all. Note that, if there are issues related to database access, a SQLException will be thrown. So, I would suggest you to first do a printStackTrace in the catch block to see if that is the case.

Also, please UseCodeTags (<--link) when posting code.


Thanks all.
 
Don't get me started about those stupid light bulbs.
 
subject: Jtable
 
Similar Threads
Please help with NullPointerException
How can i get the data to a drop down box from database
Table Viewer GUI from a Database
Datasource url database name not known until after a Batch step
Updating page when uploading files