Forums Register Login
JSTL sql tag
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}">
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
driver=" "
url=" "
user=" "
<sql:transaction dataSource="${example}">
<sql:update var="newTable">
create table mytable (
nameid int primary key,
name varchar(80)
<sql:update var="updateCount">
INSERT INTO mytable VALUES (1,'Paul Oakenfold')
<sql:update var="updateCount">
INSERT INTO mytable VALUES (2,'Timo Maas')
<sql:update var="updateCount">
INSERT INTO mytable VALUES (3,'Paul van Dyk')
<sql:query var="deejays">
SELECT * FROM mytable
if your driver name and other is correct, then 100% you will get your output, I've worked on this program
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
global solutions you can do at home or in your backyard

This thread has been viewed 1350 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 23, 2019 12:05:48.