Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Jsp Error Cant Get Data from database (http://www.programmingforums.org/showthread.php?t=13408)

lucifer Jun 22nd, 2007 3:55 AM

Jsp Error Cant Get Data from database
 
Hi
i am writing a JSP page which connects to Mysql DataBase
i can get the connection but i cant get to execute the query on the database
plz help

the code of jsp file
:

<%@ page import ="java.lang.*" %>
<%@ page import ="java.sql.*" %>
<html>
<head>
<title>
Index Page
</title>
</head>
<body>
jsp pages is better than ASP.NET
<%
int x;

Connection conn=null;
Statement st=null;
ResultSet rt=null;
String query="select * from user";

        Class.forName("com.mysql.jdbc.Driver").newInstance();
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","aaaa");
       
   
   
        out.print("<br>"+"Connection"+conn+"<br>");
        try
{
        st = conn.createStatement();
        rt=st.executeQuery("select * from a.a");
        while(rt.next())
        {
                String y;
                String str;
                x=rt.getInt("id1");
                y= rt.getString("id2");
                str= rt.getString("id3");
                out.print("id1 is"+x+"<br />");
                out.print("id2 is"+y+"<br />");
                out.print("id3 is"+str+"<br />");
        }
}
catch(Exception ex)
{
 
       
            out.print("<br>");
out.print("Timeoooo  "+"<br />"+ex);
}
finally
{
        if (rt != null) rt.close();
    if (st != null) st.close();
    if (conn != null) conn.close();
    out.print("<br>");

}


Connection con = null;
Statement str = null;
ResultSet rs = null;
 
try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con =
      DriverManager.getConnection("jdbc:mysql://localhost:3306/","root","aaaa");
 
    str = con.createStatement();
    rs = str.executeQuery("select * from a.employees");
    while(rs.next()) {
%>
<TR><TD><%= rs.getString("lname_txt") %></TD>
<TD><%= rs.getString("fname_txt") %></TD></TR>
<%
    }
%>
</TABLE>
<%
}  catch (Exception ex) {
    ex.printStackTrace();
    out.print(ex);
    %>
</TABLE>
Ooops, something bad happened:
<%
    }  finally {
    if (rs != null) rs.close();
    if (str != null) str.close();
    if (con != null) con.close();
    }
%>
</body>
</html>


msi_333 Jun 22nd, 2007 6:35 PM

what
 
What is the problem statement that appears to you ?


All times are GMT -5. The time now is 2:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC