Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

see my jsp error dscon$jsp.java [67:1] cannot resolve symbol

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir i want to use the datasource in my jsp page
i see tomcate help in connection pooling

then i set my server.xml and web.xml

server.xml
location = C:\Program Files\j2sdk_nb\netbeans3.5\tomcat406\conf\server.xml
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>
</Context>

*******

web.xml

where my all file and my project

location = F:\oraclewithjavaconn\WEB-INF\web.xml

code ==***
***********

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE web-app (View Source for full doctype...)>
- <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>

******

sir this is my jsp code for database instance in
F:\oraclewithjavaconn\conntest
*******

<HTML>
<%@ page import="java.sql.*,java.util.*" %>
<%
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>
*************

sir when i compli the page then system give me error

error*********

scon$jsp.java [67:1] cannot resolve symbol
symbol : class Context
location: class org.apache.jsp.dscon$jsp
Context initContext = new InitialContext();
^
dscon$jsp.java [67:1] cannot resolve symbol
symbol : class InitialContext
location: class org.apache.jsp.dscon$jsp
Context initContext = new InitialContext();
^
dscon$jsp.java [68:1] cannot resolve symbol
symbol : class Context
location: class org.apache.jsp.dscon$jsp
Context envContext = (Context)initContext.lookup("java:/comp/env");
^
dscon$jsp.java [68:1] cannot resolve symbol
symbol : class Context
location: class org.apache.jsp.dscon$jsp
Context envContext = (Context)initContext.lookup("java:/comp/env");
^
dscon$jsp.java [69:1] cannot resolve symbol
symbol : class DataSource
location: class org.apache.jsp.dscon$jsp
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
^
dscon$jsp.java [69:1] cannot resolve symbol
symbol : class DataSource
location: class org.apache.jsp.dscon$jsp
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
^
6 errors
Errors compiling dscon.
************

sir please give me idea how i use datasource in my jsp page

thank

aamir
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Context class is in the javax.naming package, which you're not imported in your code.
 
muhammad fahim
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your reply

please guid me how i add Context class
give me location where i add Context class

how use javax.naming package
give me loation of javax.naming package

thank you

aamir
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just import this package in page directive of your jsp page as you already import other packages.


 
muhammad fahim
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi master

sir i add your give file but did not jsp page run

sir i not change in sever.xml and web.xml
some body give me idea i change in only Context.xml in META-INF folder

this is Context.xml code

<?xml version="1.0" encoding="UTF-8" ?>
<Context path="/dcp" privileged="true">
<Resource name="jdbc/postgres" auth="Container"
type=" javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:aamir"
username="muhammad" password="mfa786" maxActive="1" maxIdle="0" maxWait="-1"/>
</Context>


*********
and this is my 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();
DataSource ds = (DataSource)initContext.lookup("java:comp/env/jdbc/myOracleDataSource");
Connection conn = ds.getConnection();
%>

<br>
TEST DONE!
</HTML>

but sir jsp page give me error

javax.servlet.ServletException: Name jdbc is not bound in this Context


please give me idea how i run my jsp page

thank'
aamir
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this to be change in your jsp


hope it helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!