Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Apache Tomcat
|
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2006, 12:44 PM
Registered User
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to balarkavelidi
Default 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.
 
Old January 15th, 2006, 10:03 AM
Authorized User
 
Join Date: Dec 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You should copy the driver of the mydql to the lib directory.


JAVA Email
http://www.wisesoft.biz/





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with updating the db using servlet Behl_Neha Java Databases 1 December 24th, 2007 06:08 AM
Can JSP integrate with Servlet and run on MySQL wesleygch JSP Basics 0 April 10th, 2007 02:22 AM
servlet accessing MySql ....error simplyAns MySQL 1 January 17th, 2006 03:41 AM
Accessing Java Servlet thru DotNet r_ganesh76 General .NET 0 June 23rd, 2004 11:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.