•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 402,522 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,592 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 2444 | Replies: 19
![]() |
| |
•
•
Join Date: Jul 2007
Posts: 11
Reputation:
Rep Power: 0
Solved Threads: 0
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...
/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...
Copy that jar file into WEB-INF/lib, not into just any generic tomcat lib directory.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jul 2007
Posts: 11
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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...
•
•
•
•
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
....
Why are you trying to run the ConnBean from the jdk bin folder if you wish to access this through Tomcat? If you want to run from the command line, you need to specify the classpath. Many posts have told you how to do that. If you have a JSP/servlet app running in Tomcat that needs that ConnBean, then placing the jar in WEB-INF/lib for that app is all that you need to do.
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,230
Reputation:
Rep Power: 10
Solved Threads: 270
Here is tutorial how to set PATH and CLASSPATH for java
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the JSP Forum
- Previous Thread: getting values from drop down menu
- Next Thread: Encoding Format WEb.XMl



Hybrid Mode