Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2002
    Posts
    1

    Unanswered: problem with mysql connections to jsp

    hello
    i am not able to get my jsp to connected to my mysql database. can anyone pls help.
    this is my jsp file
    <!--first we've to import the necessary packages-->
    <!--importing packages starts-->
    <%@ page info="database handler"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="javax.servlet.*"%>
    <%@ page import="javax.servlet.http.*"%>
    <!--importing packages ends-->

    <html>
    <head><title>jsp test page on access</title></head>
    <body bgcolor=white>
    <h4>welcome this is the test pages for the jsp and names database</h4>
    <h2>here are the results stored in the database</h2>
    <h2>&nbsp;</h2>
    <h2>&nbsp;</h2>
    <%!
    Connection con;
    Statement stmt;
    ResultSet rs;
    %>

    <%
    try
    {
    out.println("jsp started");
    Class.forName("org.gjt.mm.mysql.Driver");
    out.println("class driver loaded,");
    }
    catch (Exception e)
    {
    e.printStackTrace();
    out.println("class could not be found");
    }
    try {
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection C = DriverManager.getConnection( "jdbc:mysql://localhost/myocsco_expired?user=myocsco_muthu&password=muthu" );


    out.println("connection made");

    }
    catch (Exception e)
    {
    e.printStackTrace();
    out.println("connection test has failed");
    }
    try
    {
    stmt = con.createStatement();
    out.println("statement ok");
    rs = stmt.executeQuery("SELECT * FROM user");
    out.println("tried to query");
    if(!rs.next())
    {
    out.println("Empty ResultSet");
    }
    else
    {
    out.println("<center><Table border=1 bgcolor=gray width=500>");
    while(rs.next())
    {
    out.println("<tr><td>"+ rs.getString(1)+"</td><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+ rs.getString(4)+"</td><td>"+rs.getString(5)+"</td><td>"+rs.getString(6)+"</td><td>"+rs.getString(7)+"</td><td>"+rs.getString(8)+"</td><td>"+ rs.getString(9)+"</td><td>"+rs.getString(10)+"</td></tr>");
    }
    out.println("</Table></center>");
    }

    }
    catch (Exception e)
    {
    e.printStackTrace();
    out.println("statement or query did fail");
    }
    out.flush();
    out.close();
    %>



    </body>
    </html>

    the page is at http://www.myocs.com/getda22.jsp
    thank you for your help.
    regards
    muthu

  2. #2
    Join Date
    Apr 2003
    Location
    Bangalore
    Posts
    2

    Thumbs up JSP accessing mysql

    try this

    Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
    conn = DriverManager.getConnection("jdbc:mysql://localhost/yourdb","user","password");

    to connect to the mysql database instead of what you have used earlier.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •