Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 22nd, 2007, 3:55 AM   #1
lucifer
Programmer
 
lucifer's Avatar
 
Join Date: Oct 2005
Posts: 84
Rep Power: 4 lucifer is on a distinguished road
Question 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>
__________________
"You're good... but me, I'm magic"

Last edited by lucifer; Jun 22nd, 2007 at 4:40 AM.
lucifer is offline   Reply With Quote
Old Jun 22nd, 2007, 6:35 PM   #2
msi_333
Newbie
 
msi_333's Avatar
 
Join Date: May 2007
Location: Egypt
Posts: 19
Rep Power: 0 msi_333 is on a distinguished road
Send a message via Yahoo to msi_333
what

What is the problem statement that appears to you ?
msi_333 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i automate text data and input into database? lionel84 C# 0 Jun 26th, 2005 10:35 PM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 1:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 1:27 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:49 AM.

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