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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 24 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply