LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2010, 05:58 AM   #1
Kakarot_Rathish
Member
 
Registered: Sep 2008
Posts: 35
Blog Entries: 1

Rep: Reputation: 15
com.mysql.jdbc.Driver not found


I copied a program for the web to connect to a database in java.
But there is some problem with specifying the jdbc driver in program.





/==============
Program
===================/


import java.sql.*;

public class RetriveAllEmployees{
public static void main(String[] args) {
System.out.println("Getting All Rows from employee table!");
Connection con = null;
String url = "jdbc:mysql://localhost:8080/";
String db = "sqlexamples";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM employee");
System.out.println("Employee Name: " );
while (res.next()) {
String employeeName = res.getString("emp_name");
System.out.println(employeeName );
}
con.close();
}
catch (ClassNotFoundException e){
System.err.println("Could not load JDBC driver"); System.out.println("Exception: " + e); e.printStackTrace(); }
catch(SQLException ex){
System.err.println("SQLException information");
while(ex!=null) { System.err.println ("Error msg: " + ex.getMessage());
System.err.println ("SQLSTATE: " + ex.getSQLState());
System.err.println ("Error code: " + ex.getErrorCode());
ex.printStackTrace();
ex = ex.getNextException(); // For drivers that support chained exceptions

}
}
}
}


==============================================

NO error in compilation,but when i run i got the following error.

===============================================


Station71:~/RESA/db# vim RetriveAllEmployees.java
Station71:~/RESA/db# javac RetriveAllEmployees.java
Station71:~/RESA/db# java RetriveAllEmployees
Getting All Rows from employee table!
Could not load JDBC driver
Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.70)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.70)
at java.lang.ClassLoader.loadClass(libgcj.so.70)
at java.lang.ClassLoader.loadClass(libgcj.so.70)
at java.lang.Class.forName(libgcj.so.70)
at java.lang.Class.forName(libgcj.so.70)
at RetriveAllEmployees.main(RetriveAllEmployees.java:14)

==============================================

What should i do ?
THANX in advance

Last edited by Kakarot_Rathish; 03-09-2010 at 10:47 PM.
 
Old 03-10-2010, 12:05 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Several problems here. Why not compare notes with
Gokuldas?
 
Old 03-11-2010, 12:47 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
I'd guess, you can solve some issues by installing
a genuine sun java : 1) # apt-get install sun-java6-jdk

2) # update-alternatives --config java
.. and then choose the sun java.

.....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting GNU Tar to stop when file is found Gault LaRue Linux - General 3 03-30-2007 02:56 PM
JSP and MySQL - unable to load JDBC driver jun_tuko Programming 2 09-05-2006 11:02 AM
GNU R help with converting SPSS file - object not found towsonu2003 Linux - Software 2 03-04-2006 11:30 AM
JDBC and MySQL Driver White R4bbit Debian 2 08-13-2004 04:55 PM
gcj jdbc verigoth Programming 1 06-02-2003 10:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration