943,929 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 4775
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 30th, 2007
0

facing problem in database connectivity in jsp to mysql

Expand Post »
i am writing code and also the error i am facing in database connectivity in jsp to mysql .plz help me .thanx

/code


import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.*;
import java.io.*;

public class ConnBean
{
Connection conn;
Statement st ;
public ConnBean()
{
String sqlDriver= "com.mysql.jdbc.Driver";
String hostName = "localhost:3306/";
String dbName = "mydb";
String userID = "root";
String password = "webportal";

//databse URL
String dbURL = "jdbc:mysql://" + hostName + dbName;

try {
Class.forName(sqlDriver);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(dbURL, userID, password);
st = conn.createStatement();
System.out.println("db connected");
}
catch (SQLException e) {

System.out.println("Exception occured during get connection" + e);
}
}

public static void main(String asdas[]) throws SQLException
{

ConnBean conn=new ConnBean();


//ResultSet rs=conn.executeQ("select * from clients");
}
}

/code
and the error that jdk 1.5 ( with mysql 5.0.41) is showing is
C:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - D:\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;c:\program files\java\jdk1.5.0\lib\tools.jar;c:\program files\java\jdk1.5.0\jre\lib\rt.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at ConnBean.<init>(ConnBean.java:25)

at ConnBean.main(ConnBean.java:44)

Exception occured during get connectionjava.sql.SQLException: No suitable driver

Process Exit...
Similar Threads
Reputation Points: 9
Solved Threads: 0
Newbie Poster
muskan is offline Offline
11 posts
since Jul 2007
Jul 30th, 2007
0

Re: facing problem in database connectivity in jsp to mysql

Make sure you have "com.mysql.jdbc.Driver" in your web application. It will be contained in a .jar and it needs to go with your other java libraries you use.
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jul 31st, 2007
0

Re: facing problem in database connectivity in jsp to mysql

please tell me which .jar file has to saved and where in jdk or in tomcat althought i have mysql-connector-java-3.0.8-stable-bin.jar file that i have copied in tomcat in libs .please tel are u talking about this .jar file now wat i have to do?please guide me kindly
Reputation Points: 9
Solved Threads: 0
Newbie Poster
muskan is offline Offline
11 posts
since Jul 2007
Jul 31st, 2007
0

Re: facing problem in database connectivity in jsp to mysql

I don't know what .jar the mysql driver is in. It shouldn't be that hard to find with a google. The .jar file goes into your web app directory under "WEB-INF\lib".
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jul 31st, 2007
0

Re: facing problem in database connectivity in jsp to mysql

Copy that jar file into WEB-INF/lib, not into just any generic tomcat lib directory.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 31st, 2007
0

Re: facing problem in database connectivity in jsp to mysql

Click to Expand / Collapse  Quote originally posted by masijade ...
Copy that jar file into WEB-INF/lib, not into just any generic tomcat lib directory.

yes i have copied the .jar files in WEB-INF/lib but still when i have compiled database connectivity program with mysql in java it gave the same error.

D:\Program Files\Java\jdk1.5.0\bin\java.exe ConnBean
Working Directory - C:\final project\jsp code\
Class Path - .;c:\Kawapro5.0\kawaclasses.zip;d:\program files\java\jdk1.5.0\lib\tools.jar;d:\program files\java\jdk1.5.0\jre\lib\rt.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at ConnBean.<init>(ConnBean.java:25)

at ConnBean.main(ConnBean.java:44)

Exception occured during get connectionjava.sql.SQLException: No suitable driver

Process Exit...
Reputation Points: 9
Solved Threads: 0
Newbie Poster
muskan is offline Offline
11 posts
since Jul 2007
Jul 31st, 2007
0

Re: facing problem in database connectivity in jsp to mysql

Is there any need to copy the .jar files(that are mysql-connector-java-3.0.8-stable-bin) in jdk.If so then where these files should be copied in order to include in the class path of java.please answer it to solve my problme.thanx
Reputation Points: 9
Solved Threads: 0
Newbie Poster
muskan is offline Offline
11 posts
since Jul 2007
Jul 31st, 2007
0

Re: facing problem in database connectivity in jsp to mysql

Here is tutorial how to set PATH and CLASSPATH for java
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Aug 5th, 2007
0

Re: facing problem in database connectivity in jsp to mysql

I have the same problem. Try to copy MySQL connector jar file to
%JAVA_HOME%/jre/lib/ext/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Xolera is offline Offline
3 posts
since Aug 2007
Aug 6th, 2007
1

Re: facing problem in database connectivity in jsp to mysql

Click to Expand / Collapse  Quote originally posted by Xolera ...
I have the same problem. Try to copy MySQL connector jar file to
%JAVA_HOME%/jre/lib/ext/
Bad, bad, bad. Never copy anything to the lib/ext directory of the jre. Learn how to use and set classpaths properly. If he has the proper jarfile, and places it in the WEB-INF/lib directory of the web application he is trying to reach, the classes will be found. If they are not, he has done something wrong. Either copied it to the lib directory of the wrong application, not copied the right jarfile, or, maybe, somehow or another, changed the tomcat configuration so that it does not look there. Sorry to say it, but all of those things are "his problem", and copying anything to the lib/ext directory is not the answer, regardless of whether or not "it works".
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: day in a calender
Next Thread in JSP Forum Timeline: Encoding Format WEb.XMl





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC