Results 1 to 19 of 19
Thread: mysql classpath ubuntu problem
- 08-29-2009, 06:55 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 26
- Rep Power
- 0
mysql classpath ubuntu problem
i am using ubuntu and i have installed mysql in it and tring to connect to mysql through following java program but it is giving error:
java.lang.ClassNotFoundException: con.mysql.jdbc.Driver
Java Code:import java.sql.*; class f{ public static void main(String s[])throws Exception{ try{ Connection con; Statement stmt; ResultSet rs; Class.forName("con.mysql.jdbc.Driver").newInstance(); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata","root","ubuntu"); stmt=con.createStatement(); rs=stmt.executeQuery("select * from table1"); while(rs.next()){ System.out.println(rs.getString("id")+"\t"+rs.getString("data")+"\t"+rs.getString ("timestamp")); } }catch(Exception e){ System.out.println(e); } } }
- 08-29-2009, 07:00 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you added that jar file into your class path. Actually I'm not sure how it done in Ubuntu. Read some materials on that. The error cause the VM cannot find the package you mentioned in the required place.
- 08-29-2009, 08:19 PM #3
No matter if it is Ubuntu in windows or Linux, you should insert your mysql<version>.jar in the class path
- 08-30-2009, 12:04 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 26
- Rep Power
- 0
thanks for rply can u tell me about the drivers needed and how to set classpath
because i tried many commands for setting up classpath with driver :mysql-connector-java-5.0.6-bin.jar i think the driver is right but i am not setting my classpath write
- 08-30-2009, 05:41 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you read any documentation related to that?
- 08-30-2009, 07:33 PM #6
Member
- Join Date
- Jul 2009
- Posts
- 26
- Rep Power
- 0
i solve the problem ,i followed the following steps:
driver required are :
sudo aptitude install libmysql-java
command for classpath:
export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar
- 08-31-2009, 04:19 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Fine, if you have solve the problem please mark the thread as solved.
- 11-21-2009, 11:42 PM #8
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
command for classpath:
First, let me say I'm an old guy, not in any school course or anything.
If you are going to suggest reading, be specific please.
That said, I have read a lot, but I'm not clear on the "export" talked about here.
My current project and resulting question was exactly the same as the thread originator munish
But I don't know where to put the export CLASSPATH statement.
I've tried several spots ( .bashrc ) and a couple others that i read about.
I'm a linux, ubuntu, java beginner, so if you have an answer it needs to take that into account.
Thanks
- 11-22-2009, 04:59 AM #9
Member
- Join Date
- Jul 2009
- Posts
- 26
- Rep Power
- 0
export comand is basically for setting the classpath in ubuntu........
for running mysql statements you have to write this statement in terminal
export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar
for this u have to download mysql-connector-java.jar from mysql site and before all this u should type this command in terminal for driver : sudo aptitude install libmysql-java.
- 08-19-2010, 01:48 AM #10
Member
- Join Date
- Aug 2010
- Posts
- 5
- Rep Power
- 0
Hello,
I am a new Bee.
MySql connector can connects NetBeans Java file but I cannot connect from JSP file.
I am using tomcat and my jsp file is placed in WebApps folder.
I have set the class path in .bashrc file as bellow
export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java-5.1.13-bin.jar
and the jar file is placed in that location but the index.jsp file gives me this error
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Here is my JSP source code
<%@page
import = "java.sql.*"
import = "java.util.Properties"
%>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost/java_mysql_db";
String userName = "root";
String password = "root";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection(url,userName,password) ;
out.println("Connected<br/>");
}
catch(Exception e) {
out.println(e);
}
%>
some forum says to keep the connector jar file into the Webserver lib folder but I cannot find lib folder of Tomcat as well.
Need help :'( struggling for last few days.
thanks
- 08-19-2010, 02:46 AM #11
Member
- Join Date
- Aug 2010
- Posts
- 5
- Rep Power
- 0
Now I have keept the connector jar file in these locations
/var/lib
/var/lib/tomcat6/webapps/projects
/var/lib/tomcat6/webapps
/var/lib/tomcat6/
/lib
/usr/share/mysql-common
/usr/share/tomcat6/lib
/usr/share/tomcat6/bin
nothing working ... i am sure i am missing something but do not know what ... so frustrating :|
- 08-19-2010, 02:00 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This is an old thread, so why didn't you start a new thread? Please do it in best next time.
- 08-19-2010, 02:03 PM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Regarding your question, I wonder that you've properly set the classpath. Open your console and type the following command.
java com.mysql.jdbc.Driver
What happen?
- 08-20-2010, 06:18 AM #14
Member
- Join Date
- Aug 2010
- Posts
- 5
- Rep Power
- 0
Thanks for the response. I will make new thread next time.
I get this error from terminal after writing that command
"Exception in thread "main" java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver"
then what should i set as a path, i have set this in .bashrc
export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar
In that directory i have another package named mysql-connector-java-5.1.6.jar, so I also tried
export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java-5.1.6.jar
thanks.
- 08-20-2010, 08:02 AM #15
Member
- Join Date
- Aug 2010
- Posts
- 5
- Rep Power
- 0
Anyway, Thanks you.
I have solved it by reinstalling latest netbenas by downloading that from their site and remove my old one. and then include the connector jar file for the project. Now its working fine.
your forum is really helpful.
thanks.
- 08-20-2010, 02:01 PM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 08-20-2010, 02:04 PM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 08-22-2010, 12:15 AM #18
Member
- Join Date
- Aug 2010
- Posts
- 5
- Rep Power
- 0
- 08-22-2010, 01:55 AM #19
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If so something wrong with the classpath in drivers. Anyway it's fixed with the installations, means new classpath entries are added.
Similar Threads
-
classpath problem
By shwein in forum New To JavaReplies: 4Last Post: 04-01-2009, 12:32 PM -
Problem with CLASSPATH for STRUTS
By bhupal4all in forum Web FrameworksReplies: 2Last Post: 11-07-2008, 05:48 AM -
Eclipse / Mysql problem
By jdevm in forum EclipseReplies: 0Last Post: 10-09-2008, 01:16 AM -
mysql driver problem
By mokingsu in forum JDBCReplies: 4Last Post: 01-17-2008, 05:27 PM -
Mysql problem
By Nick15 in forum JDBCReplies: 2Last Post: 05-15-2007, 05:07 PM


LinkBack URL
About LinkBacks


Bookmarks