com.mysql.jdbc.Driver Exception !
Hey everyone, Hoe you're just fine, despite I run that code at the lab. in the university without error, but it just does not work on my pc, everytime i run that program, I got com.mysql.jdbc.Driver, how the database works fine and I make queries and updates to the table inside, but I just can't use java to make queries and updates, here's the code :
Code:
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class MyProcedure extends javax.swing.JFrame {
public MyProcedure() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
txtid = new javax.swing.JTextField();
load = new javax.swing.JButton();
txtname = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
load.setText("Load");
load.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(107, 107, 107)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txtname, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(load, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtid, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE))
.addContainerGap(124, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(load)
.addGap(18, 18, 18)
.addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(180, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void loadActionPerformed(java.awt.event.ActionEvent evt) {
Connection cn = null;
String url = "jdbc:mysql://127.0.0.1:3306/alaa";
String user ="root";
String pass = "123";
try {
int i = Integer.parseInt(txtid.getText());
Class.forName("com.mysql.jdbc.Driver").newInstance();
cn = DriverManager.getConnection(url,user,pass);
CallableStatement cs = cn.prepareCall(" call MaProcedure(?)");
cs.setInt(1, i);
ResultSet rs = cs.executeQuery();
while(rs.next()){
txtname.setText(rs.getString(2));
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyProcedure().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton load;
private javax.swing.JTextField txtid;
private javax.swing.JTextField txtname;
// End of variables declaration
}
Note: I have broadband cable installed on my pc .
please help me out figuring out what's wrong with ma code .
thank you