This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

JSTL sql tag

 
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
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic