Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

pls help me deal with jsp--oracle database connection

 
amanda wu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
please help me,
my code below connect to an oracle database.
but the code never print out data in database,
but the line"not ok".
i have checked many times, and don't know the reason.
is it due to the code or i put the driver in wrong place?
where should i put the oracle driver then?
i would appreciate your help very much if u can figure it out for me
sincerely
<html><head><title>test db</title></head>
<body>
<%@ page import="java.sql.*"%>
<table border =1 width ="75%">
<tr><th>log_time</th><th>session_id</th><th>message_body</th></tr>
<%
Connection conn=null;
Statement st=null;
ResultSet rs=null;
String dbURL="jdbc racle:thin:@202.79.195.44:1521 btest";
String username="igdnet";
String password="igdnet";
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(dbURL,username,password);
st=conn.createStatement();
rs=st.executeQuery("Select * from T_Session_Logs;");

while(rs.next()){
%>
<tr><td><%=rs.getString("Log_Time")%></td>
<td><%=rs.getString("Session_ID")%></td>
<td><%=rs.getString("Message_Body")%></td></tr>
<%
}
%>
</table>
<%
}
catch (Exception e){
e.printStackTrace();
%>
</table>
not ok:
<%
}finally{
if (rs!=null)rs.close();
if (st!=null)st.close();
if (conn!=null) conn.close();
}
%>
</body></html>
 
Rajat
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi
U can try with
rs=st.executeQuery("Select * from T_Session_Logs");
It may help.
Probably, query should wrong..........
if it does not help then print the exception
out.println(e);
 
amanda wu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
thank you very much,
finally i made it run
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, seek help and Funny Tell

Welcome to JavaRanch! Please adjust your display names to meet the JavaRanch Naming Policy.
You can change it here.

Thanks!
 
    Bookmark Topic Watch Topic
  • New Topic