help find any error jsp connect to mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bylum
    New Member
    • Mar 2007
    • 15

    help find any error jsp connect to mysql

    <%@ page import="java.sq l.*" %>
    <%
    String connectionURL = "jdbc:mysql ://localhost:3306/mysql?user=root ;password=123";
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    %>

    <html><body>

    <%
    Class.forName(" com.mysql.jdbc. Driver").newIns tance();
    connection = DriverManager.g etConnection(co nnectionURL, "root", "123");
    statement = connection.crea teStatement();
    rs = statement.execu teQuery("SELECT * FROM user");




    out.println("<t able border=1>");
    while (rs.next()) {
    out.println("<t r><td>");
    out.println(rs. getString("Host ")+"<br>");
    out.println("</td></tr>");
    }
    out.println("</table>");


    rs.close();
    %>

    </body></html>
  • jijoja
    New Member
    • Mar 2007
    • 5

    #2
    I am not sure you do stuff like that:
    out.println(rs. getString("Host ")+"<br>");
    Even before that try to avoid using "Select * from user";
    What if alter your table tomorrow? You whole code will meaningless. Put in names of columns that you want to get out of your table.
    Let's say "Select username, userpasswrod, host from user".
    Then you can use this line rs.getString(3) ;
    Try it.


    Originally posted by bylum
    <%@ page import="java.sq l.*" %>
    <%
    String connectionURL = "jdbc:mysql ://localhost:3306/mysql?user=root ;password=123";
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    %>

    <html><body>

    <%
    Class.forName(" com.mysql.jdbc. Driver").newIns tance();
    connection = DriverManager.g etConnection(co nnectionURL, "root", "123");
    statement = connection.crea teStatement();
    rs = statement.execu teQuery("SELECT * FROM user");




    out.println("<t able border=1>");
    while (rs.next()) {
    out.println("<t r><td>");
    out.println(rs. getString("Host ")+"<br>");
    out.println("</td></tr>");
    }
    out.println("</table>");


    rs.close();
    %>

    </body></html>

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by bylum
      <%@ page import="java.sq l.*" %>
      <%
      String connectionURL = "jdbc:mysql ://localhost:3306/mysql?user=root ;password=123";
      Connection connection = null;
      Statement statement = null;
      ResultSet rs = null;
      %>

      <html><body>

      <%
      Class.forName(" com.mysql.jdbc. Driver").newIns tance();
      connection = DriverManager.g etConnection(co nnectionURL, "root", "123");
      statement = connection.crea teStatement();
      rs = statement.execu teQuery("SELECT * FROM user");




      out.println("<t able border=1>");
      while (rs.next()) {
      out.println("<t r><td>");
      out.println(rs. getString("Host ")+"<br>");
      out.println("</td></tr>");
      }
      out.println("</table>");


      rs.close();
      %>

      </body></html>
      What error are you getting?

      Comment

      Working...