#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    1
    Rep Power
    0

    jsp(java)/mysql connection


    Hello
    i have downloaded sql which i seem to connect to fine using doc command.Does any one know how to connect to mysql using JAVA or preferably JSP? only connection code please without the quries or html .
    I have a piece of code below which i have tried to use unsuccessfully.
    I get error message.

    <%
    try
    {
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    }
    catch (Exception E)
    {
    System.err.println("Unable to load driver.");
    E.printStackTrace();
    }
    Connection conn =
    DriverManager.getConnection("jdbc:mysql://localhost:8080/PROJ");
    Statement statement = conn.createStatement();
    String sql = "SELECT * FROM LOGINS";
    ResultSet rs = statement.executeQuery(sql);
    while(rs.next()) {
    %>
    <tr>
    <td><%= rs.getString("customerID") %></td>
    <td><%= rs.getString("username") %></td>
    <td><%= rs.getString("password") %></td>
    <td><%= rs.getString("logintype") %></td>
    </tr>
    <% } %>

    <% if(statement != null)
    statement.close();
    if(conn != null)
    conn.close();
    %>
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    0
    Rep Power
    0
    First:
    - Did you download the JDBC Driver for mm.mysql? If not, you need to do so and add it to your classpath

    Second:
    - MySQL does not typically run on port 8080, that is for the web server. It usually runs on port 3306 by default.

    Third:
    - I might be wrong here but are you sure that you're using the right URL to connect? "jdbc:mysql://localhost:8080/PROJ" doesn't seem right to me.

    Fourth:
    - It doesn't specify anywhere your username and password so there is no authentication done. From what little I've worked with (on MySQL), you need to provide this information to connect.

    hope this helps in helping your problem

IMN logo majestic logo threadwatch logo seochat tools logo