Jsp Error

hi all

I am learning to access the database from jsp...

have installed all stuff (jdk ,tomcat ,database on my comp...

I get an error as follows

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 7 in the jsp file: /SimpleJSP.jsp

oracle.jdbc.driver.OracleDriver cannot be resolved to a type

4: <%! Connection conn; %>

5: <%! Statement stmt; %>

6: <%! ResultSet rset; %>

7: <% DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); %>

can some one suggest ....

ta

sunny

[636 byte] By [GloomyProgrammera] at [2007-11-27 4:41:31]
# 1
have you placed the Oracle's Implementation jar at /WEB-INF/lib folder if you don't please do it. and what is the reason for you to manually register the driver are you can very well use Class.forName("oracle.jdbc.driver.OracleDriver") for it.REGARDS,RaHuL
RahulSharnaa at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi RaHuL..

could u explain in detail?

what is Oracle's Implementation jar?

do u mean the username/passwd of database....?

since I am learning to code ...i have copied this code from a book and after the error code below is the code for making a connection to db

<% conn = DriverManager.getConnection("jdbc:oracle:thin:@mydatabasel:1521:Oracle","scott","tiger"); %>

GloomyProgrammera at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

well it is quite simple to connect to the DB java needs to use Oracle Driver and for that oracle provides you a jar which would be something with name orai18n.jar

...etc

now while running Jsp we need to make sure we have that jar in our class path.

there are few set of standards followed for it when deploy your webapplication there would a folder called WEB-INF and as a sub folder to it there would be a folder called lib now you have to place appropriate .jar file there.

the actual path would be something like the one wrt to tomcat

%CATLINA_HOME%\webapps\<webapplicationname>\WEB-INF\lib this is where you need to place all your libararies which you want to include &

%CATLINA_HOME%\webapps\<webapplicationname>\WEB-INF\classes

here is where you have to place all your .class files.

Hope that makes things clear for your if it doesn't

however,I'd advice you to go through below links which can make life much simple for you.

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/DEA2eTOC.html

and

http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#00_01

REGARDS,

RaHuL

RahulSharnaa at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> well it is quite simple to connect to the DB java

> needs to use Oracle Driver and for that oracle

> provides you a jar which would be something with name

> orai18n.jar

...etc

> now while running Jsp we need to make sure we have

> that jar in our class path.

> there are few set of standards followed for it when

> deploy your webapplication there would a folder

> called WEB-INF and as a sub folder to it there would

> be a folder called lib now you have to place

> appropriate .jar file there.

>

> the actual path would be something like the one wrt

> to tomcat

>

> %CATLINA_HOME%\webapps\<webapplicationname>\WEB-INF\li

> b this is where you need to place all your libararies

> which you want to include &

> %CATLINA_HOME%\webapps\<webapplicationname>\WEB-INF\cl

> asses

> here is where you have to place all your .class

> files.

>

> Hope that makes things clear for your if it doesn't

> however,I'd advice you to go through below links

> which can make life much simple for you.

>

> http://java.sun.com/blueprints/guidelines/designing_en

> terprise_applications_2e/DEA2eTOC.html

>

> and

>

> http://www.oracle.com/technology/tech/java/sqlj_jdbc/h

> tdocs/jdbc_faq.htm#00_01

>

>

>

> REGARDS,

> RaHuL

Hi RaHuL,

Can you tell me the name of the file for Oracle 9i release 2 database ?

ta

Sunny

GloomyProgrammera at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

well you may get relevant driver by going on to

http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

and the once for Oracle 9i release 2 could be found

http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html

and you may use the below article for installations & stuffs

http://docs.info.apple.com/article.html?artnum=75145

REGARDS,

RaHuL

RahulSharnaa at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

hi RaHuL...

Many thanks for you help...

I was able to progress ..a bit further...

bit stuck in the last error.

org.apache.jasper.JasperException: An exception occurred processing JSP page /SimpleJSP.jsp at line 37

34:

35: %>

36:

37: <% stmt = conn.createStatement(); %>

38:

39: <HTML>

40:

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)

javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

here is my code .....................

<%@ page import="java.sql.*" %>

<%@ page import="oracle.sql.*" %>

<%@ page import="oracle.jdbc.driver.*" %>

<%! Connection conn = null; %>

<%! Statement stmt= null ; %>

<%! ResultSet rset; %>

<%-- DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); --%>

<%-- conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oraval","scott","tiger"); --%>

<%

try {

// Load the JDBC driver

String driverName = "oracle.jdbc.driver.OracleDriver";

Class.forName(driverName);

// Create a connection to the database

String serverName = "localhost";

String portNumber = "1521";

String sid = "myora";

String url = "jdbc:oracle:thin:@localhost:1521:myora";

String username = "scott";

String password = "tiger";

conn = DriverManager.getConnection(url, username, password);

} catch (ClassNotFoundException e) {

// Could not find the database driver

} catch (SQLException e) {

// Could not connect to the database

}

%>

<% stmt = conn.createStatement(); %>

<HTML>

<HEAD>

<TITLE> List Of Departments </Title>

</HEAD>

<BODY>

<H1> List of Departments</H1>

<TABLE BORDER="1">

<TR>

<TH>ID</TH>

<TH>NAME</TH>

<TH>LOCATION</TH>

</TR>

<% rset = stmt.executeQuery("Select deptno,dname,loc from dept"); %>

<% while (rset.next()) { %>

<TR>

<TD><% rset.getInt(1); %></TD>

<TD><% rset.getString(2); %></TD>

<TD><% rset.getString(3); %></TD>

</TR>

<% } %>

</TABLE>

</BODY>

</HTML>

<% if (rset != null) rset.close(); %>

<% if (stmt != null) stmt.close(); %>

<% if (conn != null) conn.close(); %>

GloomyProgrammera at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

> well you may get relevant driver by going on to

>

> http://www.oracle.com/technology/software/tech/java/sq

> lj_jdbc/index.html

>

> and the once for Oracle 9i release 2 could be found

> http://www.oracle.com/technology/software/tech/java/sq

> lj_jdbc/htdocs/jdbc9201.html

>

> and you may use the below article for installations &

> stuffs

> http://docs.info.apple.com/article.html?artnum=75145

>

>

> REGARDS,

> RaHuL

******************************************************************************

Hi Rahul,

please help me with this one also..

My ex co-worker抯 application was RHL 7.2, Oracle 8.1.7, jakarta-tomcat-3.2.3, jdk1.3.1_01, and when installing oracle using jdk118_v3. The application works fine but for some reason my Boss told me to replatform it.

So I抦 trying to re platform it using Red Hat AS 3, apache-tomcat-6.0.10, jdk1.6.0_01(I use it cause that's the one available for d/l and suitable for tomcat6. ) , and Oracle 9.2.0. When installing oracle I temporarily switch java to jdk118_v3. and I can connect to mysceme through sqlplus. I switch the java back to 1.6.0 (ln - s jdk1.6.0_01 java)

I put jk.conf on /etc/httpd/conf.d. I can see tomcat web page on http://localhost.

I assume Tomcat and httpd2 seems to work fine.

I had copy the $HOME_ORACLE/jdbc/lib/classes111.zip to /usr/local/java/lib

I had set CLASSPATH to: /usr/local/java/lib/tools.jar:/usr/local/java/lib/classes111.zip

Then I put the application (my ex-co-worker's) on $CATALINA_HOME/webbaps/myapps/

And i have copy all the file from $ORACLE_HOME/jdbc/lib to <myapps>/WEB-INF/lib

Now I抦 having problem when accessing http://localhost/myapps/index.jsp.

Index.jsp is including the paramconn.jsp script, which suppose to connect to Oracle. Here抯 the err msg :

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 11 in the jsp file: /admin/paramconn.jsp

oracle.jdbc.driver.OracleDriver cannot be resolved to a type

8: Connection conn2=null;

9: String connStr="jdbc:oracle:thin:@mydbserver:1521:SIDSVR01";

10: try {

11: DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

12:conn = DriverManager.getConnection(connStr,"myscheme","schemepwd");

13: }catch(SQLException e) {

14: out.println(e.getMessage());

This is the /admin/paramconn.jsp :

<%@ page import="java.sql.*" %>

<%@ page import="java.net.*" %>

<%@ page import="java.util.*" session="true"%>

<%@ page import="java.util.Enumeration" %>

<%

Connection conn=null;

Connection conn2=null;

String connStr="jdbc:oracle:thin:@mydbsvr:SIDSVR01";

try {

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

conn = DriverManager.getConnection(connStr,"myscheme","schemepwd");

}catch(SQLException e) {

out.println(e.getMessage());

}

%>

Is it because i'm using jdk1.6.0 ? i tried switching back to jdk118 (ln -s jdk118 java) but it's stil the same.

i also had try to copy ojdbc14.jar (and the nls12) (I dont see any ojdbc16.jar) to /usr/local/lib and set the CLASSPATH. but it's still giving the same error msg.

I hope I dont have to change the application scripts alot cause i'm a bit new here.

This is getting to be frustating so do you (or anybody elses) have any suggestion ?

Sorry, for the long question.

Looking forward for your reply.

Thanks.

Regards,

Yovi

Yovia at 2007-7-12 9:52:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...