File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to save values in a database in JSTL?

 
Palani Kumar
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I store values in a database using JSTL...
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you come across SQL library of JSTL? That is exclusively designed for your purpose.

You may also what to check the following links for more information.

link1
link2
link3

[ May 29, 2008: Message edited by: Prasad Tamirisa ]
[ May 29, 2008: Message edited by: Prasad Tamirisa ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Kumar-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, it's considered bad design to perform JDBC operations in JSPs, with or without JSTL. Consider using a backing bean or -even better- a servlet instead.
 
Palani Kumar
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code i cant insert values into database... pls help me

<%@ page import="java.io.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<html>
<head>
<title>Airport</title>
</head>
<body>
<c:import var="students" url="http://service.openkapow.com/palanikumar/airportbarbados.rest" />
<x:parse var="doc" xml="${students}" />
<table border="1">
<tr>
<th>AirportName</th>
<th>Location</th>
<th>Airport Overview</th>
<th>ByBus</th>
<th>ByTaxi</th>
<th>ByTrain</th>
<th>PhoneNum</th>
<th>Website</th>
</tr>
<x:forEach var="result" select="$doc/result">
<tr>
<td>
<xut select="$result/AirportName" />
</td>
<td>
<xut select="$result/Location" />
</td>
<td>
<xut select="$result/ByBus" />
</td>
<td>
<xut select="$result/ByTaxi" />
</td>
<td>
<xut select="$result/ByTrain" />
</td>
<td>
<xut select="$result/PhoneNum" />
</td>
<td>
<xut select="$result/Website" />
</td>
</tr>
</x:forEach>
</table>
</body>
</html>
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The page doesn't contain any JDBC/SQL code, so I'm not sure how it could insert anything in a DB?
[ May 29, 2008: Message edited by: Ulf Dittmer ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kumar Ranch", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
Palani Kumar
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my code... This is not inserting values into database... Whts wrong in my code... Pls help me..
<?xml version="1.0" encoding="ISO-8859-1"?>
<students>
<student id="1">
<name>
<first>Joe</first>
<last>Y</last>
<middle>T</middle>
</name>
<grade>
<points>99</points>
<letter>A</letter>
</grade>
</student>
<student id="2">
<name>
<first>James</first>
<last>Todd</last>
<middle>K</middle>
</name>
<grade>
<points>92</points>
<letter>B</letter>
</grade>
</student>
<student id="3">
<name>
<first>Kate</first>
<last>Wang</last>
<middle>A</middle>
</name>
<grade>
<points>72</points>
<letter>C</letter>
</grade>
</student>

</students>

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<html>
<head>
<title>Set Examples</title>
<sql:setDataSource driver="sun.jdbc.odbc.JdbcOdbcDriver" url="jdbcdbc:db1" var="db1" />

</head>

<body>
<c:import var="students" url="students.xml" />

<x:parse var="doc" xml="${students}" />

<x:set var="a" select="$doc/students/student/name/first" />

<x:set var="b"
select="$doc/students/student/name/last" />

<x:set var="c"
select="$doc/students/student/name/middle" />

<table border="1">
<tr>
<td>$doc/students/student/name/first</td>

<td>
<xut select="$a" />
</td>
</tr>

<tr>
<td>$doc/students/student/name/last</td>

<td>
<xut select="$b" />
</td>
</tr>

<tr>
<td>$doc/students/student/name/middle</td>

<td>
<xut select="$c" />
</td>
</tr>
</table>

<sql:update var="query1" dataSource="${db1}" sql="insert into studentDetails

values('${a}','${b}')">
</sql:update>
<cut value="record added"/>
<c:forEach var="row" items="${query1.rowsByIndex}" >
<tr>
<td> <cut value="${row.first}" /></td>
<td> <cut value="${row.last}" /></td>
<td> <cut value="${row.middle}" /></td>
</tr>
</c:forEach>

</table>
</body>
</html>
[ May 30, 2008: Message edited by: Palani Kumar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic