JSTL sql setDataSource

JSTL sql setDataSource


Posted in : Java Posted on : April 20, 2012 at 7:38 PM Comments : [ 0 ]

In this tutorial you will learn about the JSTL sql tag setDataSource.

JSTL sql setDataSource

In this tutorial you will learn about the JSTL sql tag setDataSource.

This tag is used to create a DataSource configuration that may be stored into a variable which can be provided as an input to another JSTL database-action.

Attributes of setDataSource :

  • var : This attribute is optional that specifies the name of the variable or stores a value of the specified data source.
  • scope: This attribute is optional that specifies the scope of a variable.
  • dataSource : This attribute is optional that specifies the data source.
  • driver : This is an optional attribute that specifies the JDBC driver class name.
  • url : This is an optional attribute that specifies the JDBC URL associated with the database
  • user : This is an optional attribute that specifies the JDBC database user.
  • password : This is an optional attribute that specifies the JDBC user password.

Example :

Here I am giving a simple demo example which will demonstrate you about the JSTL <sql:setDataSource> tag. In this example I have created a JSP page where I have used the <sql:setDataSource> to create a DataSource.

JstlSqlSetDataSourceDemo.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL sql:setDataSource Example</title>
</head>
<body>
<sql:setDataSource var="ds" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.10.13/data"
user="root" password="root"/>
</body>
</html>

In the above example attributes of <sql:setDataSource> var stores the value of specified data source, driver specifies the JDBC driver name, url specifies the JDBC url associated with the database, user specifies the database user to made the connection on behalf of the user with the database, password specifies the password of the user on whose behalf the connection is made.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics