Have you tried to put the port 3306 after the host? I assume you are in
the localhost.

> Not sure if this is the place to ask but hopefully someone can help me
> here.  I am setting an application system and have successfully setup
> MySQL 5.0.15 and Tomcat 5.5.12.  However, I cannot seem to get a
> connection object from my servlet and for the life of me, I can't figure
> out why.  Here is what I have done:
>
> Downloaded  mysql-connector-java-3.1.11-bin.jar into
> $CATALINA_HOME/common/lib
> Added mysql-connector-java-3.1.11-bin.jar to my classpath
>
> and I created the following servlet, TestSQL:
>
> import java.sql.*;
> import javax.naming.InitialContext;
> import javax.sql.DataSource;
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> import javax.naming.*;
>
> public class TestSQL extends HttpServlet {
>     private Connection conn = null;
>
>     public void doGet(HttpServletRequest request,
>                       HttpServletResponse response)
>         throws IOException, ServletException {
>
>         response.setContentType("text/html");
>         PrintWriter out = response.getWriter();
>
>         try {
>             if (conn == null) {
>                 Class.forName("com.mysql.jdbc.Driver").newInstance();
>                 connW =
> DriverManager.getConnection("jdbc:mysql://localhost/hostname", <id>,
> <password>);
>             }
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>
>         if (conn != null) {
>             out.println("Connection read successful");
>         } else {
>             out.println("Cannot get connection");
>         }
>     }
> }
>
> I keep getting "Cannot get connection" message in my servlet.  I tried
> connecting to the database (locally) using mysql client with <id> just
> to make sure the account works and it does.  I setup a similar system
> before and was able to connect to the database successfully so I can't
> figure out what's wrong.
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>
>


-- 
Master of Applied Computer Science
Faculty of Computer Science
Dalhousie University
Halifax, Nova Scotia
Canada


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to