• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Jtable

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic