Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable

 
kamiya sei
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic