Re: why can't my servlet connect to mysql...?

Sunita Dilwali <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <[email protected]>
Try to use this code.



try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();

      } catch(ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: " + e.getMessage());
      }catch(Exception exp){
                System.err.print("some exception: "+ exp.getMessage());
}

      try {
                // Are you sure 'mysql' is the name of your database
         con =
DriverManager.getConnection("jdbc:mysql://127.0.0.1/mysql","root","root1
234");
        	
    }
             catch(SQLException ex) {
         System.err.println("-----SQLException-----");
         System.err.println("SQLState:  " + ex.getSQLState());
         System.err.println("Message1:  " + ex.getMessage());
         System.err.println("Vendor:  " + ex.getErrorCode());
      }

Sunita Dilwali
Web Master Jewish Family and Life!
90 Oak Street, Fourth Floor
P.O. Box 9129
Newton, MA 02464
Tel: 617-965-7700 x206
Fax: 617-965-7772
[email protected]


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[email protected]] On Behalf Of
Cadbury
Sent: Tuesday, July 13, 2004 6:15 AM
To: [email protected]
Subject: why can't my servlet connect to mysql...?


hi...it seems that my servlet have problem connecting
to mysql...

here's a part of my servlet code:

---------------------------------------------
public class RegisterUser extends HttpServlet{
   public void service(ServletRequest request,
        ServletResponse response)throws IOException{

        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        try{

Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection con;
con = DriverManager.getConnection
("jdbc:mysql://127.0.0.1/mysql?user=root&password=root1234");


}
catch (Exception e){
pw.println("\nError: " + e.getMessage());
}
}
}
-----------------------------------------------
i got the error message: Error: com.mysql.jdbc.Driver

any idea what did i do wrong here..? cause my another
java application can connect to mysql without any problem..using the
same syntax as above..

thanx a lot. any help are greatly appreciated.



__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

________________________________________________________________________
___
To unsubscribe, send email to [email protected] and include in the
body of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.