Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp page not show oracle data

 
muhammad fahim
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi master
Sir I use orace 9i easily in java class with following code

===========
import java.sql.*;
public class ttst {
public ttst() {
public static void main (String args [])
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbcracle:thin:@fahim:1521:aamir","muhammad","mfa786");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select accid from accbal where accid='K1101'");
System.out.println ("going for connection");
while (rset.next())
s= rset.getString("accid");
System.out.println (s);
}
catch(Exception e){
e.printStackTrace();
}
}

system give me right result

and when I use jsp with this code




<HTML>
<%@ page import="java.sql.*,java.util.*" %>
<% String url="jdbcracle:thin:@fahim:1521:aamir";
Connection con;
Statement stmt;
ResultSet rs;
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url,"muhammad","mfa786");
stmt=con.createStatement();
%>
<%

%>
<select name="ltpid">
<%
try{
rs= stmt.executeQuery("select accid,title from chartofacc");
while (rs.next()){
%>
<option Value=<%=rs.getString(1)%>> <%=rs.getString(2) %> </option>
<%
}
}
catch(Exception e){}
%>
</select>
<br>
TEST DONE!
</HTML>


sir I have class12.zip and class11.zip I same folder

but system give me this error


Apache Tomcat/4.0.6 - HTTP Status 500 - Internal Server Error

type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: oracle.jdbc.driver.OracleDriver
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)




but jsp page not run

please give me idea how I how my oracle data in jsp page

thank

aamir
 
Cm Ananth
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What is class12.zip and class11.zip ?. the same java code should work in JSP also, because the compiler will use the same way to compile JSP's as well as Java's.

I would suggest to check the syntax again.

Ananth CM
Bangalore
 
muhammad fahim
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i check my code
you also check my code


<HTML>
<%@ page import="java.sql.*,java.util.*" %>
<% String url="jdbcracle:thin:@fahim:1521:aamir";
Connection con;
Statement stmt;
ResultSet rs;
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url,"muhammad","mfa786");
stmt=con.createStatement();


%>
<%

%>
<select name="ltpid">
<%
try{
rs= stmt.executeQuery("select accid,title from chartofacc");
while (rs.next()){
%>
<option Value=<%=rs.getString(1)%>> <%=rs.getString(2) %> </option>
<%
}
}
catch(Exception e){}
%>
</select>
<br>
TEST DONE!
</HTML>


please give me idea how i run my page

thank

aamir
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
place your " try { " before class.forName()

then try..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message from your browser doesn't tell us much.

Check your server's logs and find the actual stack trace.
 
Baseet Ahmed
Ranch Hand
Posts: 225
Java Notepad Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fahim/Amir,

Use try-catch block for your code and see the exception detail.
And I think the files are classes12.zip,classes11.zip,not the one mentioned by you.See to it they are properly set(Check Classpath/lib folder of app server.)


Tip: Modesty is all virtue.
 
muhammad fahim
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank for your reply

sir you see my full coding



hi master
sir i edit my server.xml and web.xml but system give me this error

javax.servlet.ServletException: Exception creating DataSource: org.hsql.jdbcDriver


server.xml file code

**
- <Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_DBTest_log." suffix=".txt" timestamp="true" />
<Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource" />
- <ResourceParams name="jdbc/myoracle">
- <parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
- <parameter>
<name>driverClassName</name>
<value>oracle.jdbc.OracleDriver</value>
</parameter>
- <parameter>
<name>url</name>
<value>jdbcracle:thin:@127.0.0.1:1521:aamir</value>
</parameter>
- <parameter>
<name>username</name>
<value>scott</value>
</parameter>
- <parameter>
<name>password</name>
<value>tiger</value>
</parameter>
- <parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
- <parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
- <parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
<Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbcracle:thin:@127.0.0.1:1521:aamir" username="muhammad" password="mfa786" maxActive="20" maxIdle="10" maxWait="-1" />
</Context

*******

web.xml file
*********
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>testconn</servlet-name>
<servlet-class>testconn</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testconn</servlet-name>
<url-pattern>/servlet/testconn</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
<welcome-file>
index.html
</welcome-file>
<welcome-file>
index.htm
</welcome-file>
</welcome-file-list>
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>



this is my test jsp code
<HTML>
<%@ page import="java.sql.*,java.util.*" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext"%>
<%
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
%>
<br>
TEST DONE!
</HTML>

but server give me error

javax.servlet.ServletException: Exception creating DataSource: org.hsql.jdbcDriver
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
at org.apache.jsp.bistest$jsp._jspService(bistest$jsp.java:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet$JspServletWrapper.service(IDEJspServlet.java:173)
at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.serviceJspFile(IDEJspServlet.java:246)
at org.netbeans.modules.tomcat.tomcat40.runtime.IDEJspServlet.service(IDEJspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:226)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.netbeans.modules.web.monitor

sir please give me idea ho i access my oracel data in jsp page with datasource

thanks


when i complied the project the netbeans give me this error

==========
Warning: ZIP files located in the WEB-INF/lib directory are not automatically added to Tomcat's execution classpath.
See the online help topic "Setting Tomcat Installation Properties" for adding ZIP files using the External Execution Process property.
==========
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic