Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL sql tag  RSS feed

 
Amarjyoti Das
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>
 
prabhakar rao
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!