473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mysql connection .....

rohitrohitrohit
Hi every one
i am a beginner..........
i installed xampp in my computer.(php+mysql) i wrritten a code below.
but it generate a error class not found.

can i connect my servlets with mysql which i installed with xampp?


//import javax.sql.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Registration extends HttpServlet
{
private ServletContext application;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
application= config.getServletContext();
}
public void doPost(HttpServletRequest req , HttpServletResponse res) throws ServletException,IOException
{


try
{
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "mis";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String pass = "";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url+dbName,userNam e,password);
PreparedStatement pstat=con.prepareStatement("insert into registration values(?,?)");

String firstname=req.getParameter("username");
String password=req.getParameter("password");

pstat.setString(1,firstname);

pstat.setString(2,password);


int inser=pstat.executeUpdate();
if(inser==1)
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<b>Please&nbsp;Wait.......</b>");
out.println("</body>");
out.println("</html>");
res.setHeader("Refresh","5;URL= http://localhost:8000/musicsworld/jsp/RegistrationSuccess.jsp");

// The code i written below works well but after disscussion i am going to display this result through jsp
/* res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>www.MusicsInc.com</title>");
out.println("</head>");
out.println("<body bgcolor=Tan>");
out.println("<img src=\"C:/j2sdkee1.2.1/public_html/musicsworld/img/rohit.jpg\">");
out.println("<br>");
out.println("<font face=arial color=#cc3333>Thank you for Registration in our web site</font>");
out.println("<p align=Left><b><font face=arial color=#cc3333 size=6>Congratulation !&nbsp; on Successful Registration.....</font></b></p>");
out.println("<h3><font face=arial color=red>This site is Greate for fun and Masti.&nbsp;&nbsp;We hope You will Enjoy with it.&nbsp;Please Remember Your Id and password for Login.Our Private Policy Terms $ Condition Restrices Unauthories access of any Account.</h3>");
out.println("<h3><font face=arial color=red>Here your Id will your Name which you entered in Registration Form.</h3>");
out.println("<hr height= width= color=gray>");
out.println("</body>");
out.println("</html>"); */


}
}
catch(Exception e)
{




res.setContentType("text/html");
PrintWriter out=res.getWriter();

out.println("<html>");
out.println("<head>");
out.println("<title>www.MusicsInc.com</title>");
out.println("</head>");
out.println("<body bgcolor=Tan>");
out.println("<b>Your Request Failed Transaction Has Not Done</b>");
out.println("<br>");
out.println("<b>Error in connectivity...............</b>");
out.println(e);
out.println("<br>");
out.println("<b>Please Carefully Fillup Your Registration Form&nbsp;&nbsp;Filling Values Must Match As Accordidng TO Requirements...</b>");
out.println("<br>");
out.println("Remote Address: " + req.getRemoteAddr());
out.println("<br>");
out.println("PathInfo: " + req.getPathInfo());
out.println("<br>");
out.println("Protocol: " + req.getProtocol());
out.println("<br>");
out.println("Protocol: " + req.getAuthType());

out.println("<br><br><br><br>");
out.println("<hr height=600 width=400 color=gray>");
out.println("</body>");
out.println("</html>");



}
}
}
Feb 11 '08 #1
2 1526
r035198x
13,262 8TB
1.) Please use code tags when posting code
2.) What's the exact exception that you got?
3.) Why don't you use MySQL's JDBC driver for the connection. Download it from the MySQL site.
Feb 11 '08 #2
BigDaddyLH
1,216 Expert 1GB
String driver = "com.mysql.jdbc.Driver";
...
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Do you see that you don't use driver?

Also, the most important thing you should learn how to do is separate unrelated layers of code: your servlets/JSP should not have any mention of database access.

Get your database code working first, in simple example programs.
Feb 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
1
by: zMisc | last post by:
I am looking at using MySQL in my application (currently works with Access and SQL Server 2000). Is it possible to access MySQL database using ADO? What is the connection string for this? ...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
7
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
5
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
3
by: tulika dutta | last post by:
after 8 hrs my MySQL connection with JDBC gets time out. It gives the error java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.