![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 84
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#2 |
|
Newbie
|
what
What is the problem statement that appears to you ?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |