Results 1 to 7 of 7
- 06-08-2011, 11:58 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
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 :
Note: I have broadband cable installed on my pc .Java 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 }
please help me out figuring out what's wrong with ma code .
thank youLast edited by DarrylBurke; 06-09-2011 at 10:14 AM. Reason: Change QUOTE tags to CODE tags
- 06-09-2011, 04:05 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Post the full exception you are receiving. Exceptions are gold mines when it comes to debugging applications. Second, you mention using 2 computers with only 1 working - 127.0.0.0 is localhost (eg the computer you are running on), is the database and its associated tables/data installed?
- 06-09-2011, 07:47 AM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
You are using netbeans? Did you already add MySQL library to your project?
- 06-09-2011, 09:54 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
com.mysql.jdbc.Driver Exception is not an exception.
It's a fraction of the text of your exception.
You're also losing the stack trace so you'll not find out (easily) where the exception came from.
Instead of doing this:
do this:Java Code:} catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); }
to at least get a stack trace you can use.Java Code:} catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); ex.printStackTrace(); }
Oh, and use code tags, not quote tags for code.
- 06-10-2011, 12:29 AM #5
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Hey, I added ex.printStackTrace(); to the exception and running the code resulted in :
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
by the way I've already copied mysql-connector-java-5.0.8-bin file to C:\Program Files\Java\jre6\lib on my pc .
thanks a million
- 06-10-2011, 01:25 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Good news, I fixed the problem up by adding mysql-connector-java-5.0.8-bin to my project properties but can i ask, do i have to add jdbc driver to every project I create ?
- 06-10-2011, 09:30 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Then you are not finding out where the stack trace is going...it won't (for example) be printing in the JOptionPane. It will be in whatever console applies to your app (or log file).
Also, do not add libraries to your JRE (or JDK) deployment.
Answering your followup, yes. You add libraries to your applications. Different applications may require different version of a jar file.
Similar Threads
-
com.mysql.jdbc.Driver
By uthpalaw in forum EclipseReplies: 2Last Post: 10-14-2010, 05:09 AM -
JDBC Driver
By Ursula in forum New To JavaReplies: 6Last Post: 08-23-2010, 05:41 PM -
ClassNotFoundException com.mysql.jdbc.Driver
By Heather in forum JDBCReplies: 4Last Post: 03-31-2010, 12:08 PM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 01:57 AM -
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]System Exception: Connection
By Ram_TPS in forum JDBCReplies: 1Last Post: 10-16-2008, 02:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks