•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 455,962 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 3,602 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 MySQL advertiser: Programming Forums
Views: 1128 | Replies: 2
![]() |
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
HI..
I want to create an webpage such that when user will enter their username and password,the data will be stored in a database(I am using MySQL).I have the code.But when i am trying to run the servlet,its showing following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I have set the classpath of the driver
C:\apache-tomcat-4.1.36\common\lib\servlet.jar;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar
I think its ok as if i run any jdbc program without using servlet, it is working properly.
So i cant understand what to do..
Please help as soon as possible.
This is servlet code:
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletInsertingDataUsingHtml extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DATABASE_URL = "jdbc:mysql://localhost/sweta_db";
Connection connection;
try{
Class.forName( JDBC_DRIVER );
connection = DriverManager.getConnection( DATABASE_URL, "jhtp6", "jhtp6" );
String username = request.getParameter("username");
String password = request.getParameter("password");
pw.println(username);
pw.println(password);
PreparedStatement pst = connection.prepareStatement("insert into User values(?,?)");
pst.setString(1,username);
pst.setString(2,password);
int i = pst.executeUpdate();
if(i!=0){
pw.println("<br>Record has been inserted");
}
else{
pw.println("failed to insert the data");
}
}
catch (Exception e){
pw.println(e);
}
}
}
I want to create an webpage such that when user will enter their username and password,the data will be stored in a database(I am using MySQL).I have the code.But when i am trying to run the servlet,its showing following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I have set the classpath of the driver
C:\apache-tomcat-4.1.36\common\lib\servlet.jar;C:\mysql-connector-java-5.0.8\mysql-connector-java-5.0.8-bin.jar
I think its ok as if i run any jdbc program without using servlet, it is working properly.
So i cant understand what to do..
Please help as soon as possible.
This is servlet code:
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletInsertingDataUsingHtml extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DATABASE_URL = "jdbc:mysql://localhost/sweta_db";
Connection connection;
try{
Class.forName( JDBC_DRIVER );
connection = DriverManager.getConnection( DATABASE_URL, "jhtp6", "jhtp6" );
String username = request.getParameter("username");
String password = request.getParameter("password");
pw.println(username);
pw.println(password);
PreparedStatement pst = connection.prepareStatement("insert into User values(?,?)");
pst.setString(1,username);
pst.setString(2,password);
int i = pst.executeUpdate();
if(i!=0){
pw.println("<br>Record has been inserted");
}
else{
pw.println("failed to insert the data");
}
}
catch (Exception e){
pw.println(e);
}
}
}
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation:
Rep Power: 6
Solved Threads: 68
You have to set classpath in apache configuration file.
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Prroblem during Connecting Servlet with JDBC (Community Introductions)
- Internet cant connect directly! Trojan? (Viruses, Spyware and other Nasties)
- Cant connect to ebay,microsoft etc, run Steam while sharing internet conection (Networking Hardware Configuration)
- A strange problem: unplugged network cable !! (Networking Hardware Configuration)
- Problem starting windows xp.. (Windows NT / 2000 / XP / 2003)
- Router problem. Belkins (Networking Hardware Configuration)
- can't connect to any secure website (Web Browsers)
- XP cam problem with win 98 (Windows NT / 2000 / XP / 2003)
- svchost problem with Windows 2000 (Windows NT / 2000 / XP / 2003)
Other Threads in the MySQL Forum
- Previous Thread: syntax error....
- Next Thread: Need a simple mysql search script



Linear Mode