Tutorials Point


  Basic JSP Tutorials
  Advanced JSP Tutorials
  JSP Useful References
  JSP Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

JSTL SQL <sql:setDataSource> Tag


previous next AddThis Social Bookmark Button


The <sql:setDataSource> tag sets the data source configuration variable or saves the data-source information in a scoped variable that can be used as input to the other JSTL database actions.

Attribute:

The <sql:setDataSource> tag has following attributes:

AttributeDescription RequiredDefault
driverName of the JDBC driver class to be registeredNoNone
urlJDBC URL for the database connectionNoNone
userDatabase usernameNoNone
passwordDatabase passwordNoNone
passwordDatabase passwordNoNone
dataSourceDatabase prepared in advanceNoNone
varName of the variable to represent the databaseNoSet default
scopeScope of the variable to represent the databaseNoPage

Example:

Consider the following information about your MySQL database setup:

  • We are using JDBC MySQL driver.

  • We are going to connect to TEST database on local machine.

  • We would use user_id and mypassword to access TEST database.

All the above parameters would vary based on your MySQL or any other database setup. Keeping above parameters in mind, following is a simple example to use setDataSource tag:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<html>
<head>
<title>JSTL sql:setDataSource Tag</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="user_id"  password="mypassword"/>

<sql:query dataSource="${snapshot}" sql="..." var="result" />
 
</body>
</html>

You will start using <sql:setDataSource> in subsequent SQL tags.



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names