Page 1 of 1

The following is my code for my StudentDetails Gui, however when I try to connect to my database I cannot connect. How c

Posted: Fri May 20, 2022 3:33 pm
by answerhappygod
The following is my code for my StudentDetails Gui, however when
I try to connect to my database I cannot connect. How can I correct
this error and properly display my table of what is popualted in
database on my gui?
public class StudentDetailsGui extends javax.swing.JFrame {
/**
* Creates new form
* StudentDetailsGui
*/
public StudentDetailsGui() {
initComponents();

//DBConnection.getConnection();
//Student_Load();
Connect();

}
Connection con;
PreparedStatement pst;
ResultSet rs;
DefaultTableModel d;

public void Connect(){
try {

Class.forName("com.mysql.cj.jdbc.Driver");
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/studentmanage","root","");

} catch (SQLException ex)
{

JOptionPane.showMessageDialog(null,"Cannot connect!");
} catch
(ClassNotFoundException ex) {

JOptionPane.showMessageDialog(null,"Still Cannot
connect!");
}
}

public void Student_Load(){
int c;
try {
pst =
con.prepareStatement("select * from student");
rs =
pst.executeQuery();
ResultSetMetaData rsd = rs.getMetaData();
c =
rsd.getColumnCount();

d =
(DefaultTableModel)jTableData.getModel();

d.setRowCount(0);

while
(rs.next()) {

for(int i=1; i<=c; i++){


rs.getString("StudentID");


rs.getString("name");


rs.getString("surname");


rs.getString("email_address");


rs.getString("course");

}

}
} catch (SQLException ex)
{

JOptionPane.showMessageDialog(null,"Cannot display");
}
}
The Following Is My Code For My Studentdetails Gui However When I Try To Connect To My Database I Cannot Connect How C 1
The Following Is My Code For My Studentdetails Gui However When I Try To Connect To My Database I Cannot Connect How C 1 (40.68 KiB) Viewed 26 times
}//GEN-LAST:event_btnSearchActionPerformed // code for searching by studentid private void btnBackActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed // TODO add your handling code here: JOptionPane.showMessageDialog(null, "When button clicked it goes to previous GUI"); }//GEN-LAST:event_btnBackActionPerformed private void btnCancelActionPerformed (java.awt.event. ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed // TODO add your handling code here: txtStudentID.setText(""); txtStuDisplay.setText(""); cmbCourse.setSelectedIndex(); }//GEN-LAST:event_btnCancelActionPerformed private void btnExitActionPerformed (java.awt.event. ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed // TODO add your handling code here: System.exit(0); }//GEN-LAST:event_btnExitActionPerformed private void cmbCourseActionPerformed (java.awt.event. ActionEvent evt) {//GEN-FIRST:event_cmbCourseActionPerformed // TODO add your handling code here: }//GEN-LAST:event_cmbCourseActionPerformed