Accessing MySql db from a Servlet(Urgent)
hi all,
Please help me in accessing Mysql database from a servlet.I configured mysql properly that i get no errors while running a normal java application.But when i access it using a servlet i get an exception:
com.mysql.jdbc.Driver:ClassNotFoundException.
here is the part of code:
//HAVE A LOOK AT THESE IMPORTS I AM NOT SURE WHETHER TO USE THEM IN TOMCAT.
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.DocsConnectionPropsHelper;
public class xmlservlet extends HttpServlet
{
public Statement st1;
public Connection con;
public Document dom;
public int k=0;
public static String ipad="";
public Vector nod=new Vector();
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
out.println("Welcome");
String url="jdbc:mysql://localhost:3306/newdb?user=raju;password=ravi";
try
{
Class.forName("[u]com.mysql.jdbc.Driver</u>");
con=(Connection) DriverManager.getConnection(url,"raju","ravi");
out.println("connected");
st1 = (Statement) con.createStatement();
}
catch(Exception en)
{
en.printStackTrace();
out.println("Exception: " + en.toString());
}
Thanks in Advance.
vbalarka.
|