• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JSTL sql tag  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to use a datasource with JSTL <sql> tag. I am using Tomcat 4.1 with DBCP and Oracle. The code is shown below. I am receiving "datasource is null" message.
Thank you,
Amar Das
<%@ page import="javax.naming.*,javax.sql.*,java.sql.*" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%
try {
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
Context envContext = (Context)ctx.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/dqs_maoracle");
%>
<sql:query var="deejays" dataSource="${ds}">
select TABLE_NAME from USER_TABLES
</sql:query>
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear amar, the examples which are provided by the sun on SQL tags are correct only, but only thing is you need to set url,driver name, user name and password according to your database.
try this program, set your own url,driver name,user name and password in the below fields
<sql:setDataSource
var="example"
driver=" "
url=" "
user=" "
password=""
/>
<sql:transaction dataSource="${example}">
<sql:update var="newTable">
create table mytable (
nameid int primary key,
name varchar(80)
)
</sql:update>
<sql:update var="updateCount">
INSERT INTO mytable VALUES (1,'Paul Oakenfold')
</sql:update>
<sql:update var="updateCount">
INSERT INTO mytable VALUES (2,'Timo Maas')
</sql:update>
<sql:update var="updateCount">
INSERT INTO mytable VALUES (3,'Paul van Dyk')
</sql:update>
<sql:query var="deejays">
SELECT * FROM mytable
</sql:query>
</sql:transaction>
if your driver name and other is correct, then 100% you will get your output, I've worked on this program
regards
prabhakar
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!