
- Basic JSP Tutorial
- JSP - Home
- JSP - Overview
- JSP - Environment Setup
- JSP - Architecture
- JSP - Lifecycle
- JSP - Syntax
- JSP - Directives
- JSP - Actions
- JSP - Implicit Objects
- JSP - Client Request
- JSP - Server Response
- JSP - Http Status Codes
- JSP - Form Processing
- JSP - Writing Filters
- JSP - Cookies Handling
- JSP - Session Tracking
- JSP - File Uploading
- JSP - Handling Date
- JSP - Page Redirect
- JSP - Hits Counter
- JSP - Auto Refresh
- JSP - Sending Email
- Advanced JSP Tutorials
- JSP - Standard Tag Library
- JSP - Database Access
- JSP - XML Data
- JSP - Java Beans
- JSP - Custom Tags
- JSP - Expression Language
- JSP - Exception Handling
- JSP - Debugging
- JSP - Security
- JSP - Internationalization
- JSP Useful Resources
- JSP - Questions and Answers
- JSP - Quick Guide
- JSP - Useful Resources
- JSP - Discussion
JSTL - SQL <sql:setDataSource> Tag
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 the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
driver | Name of the JDBC driver class to be registered | No | None |
url | JDBC URL for the database connection | No | None |
user | Database username | No | None |
password | Database password | No | None |
password | Database password | No | None |
dataSource | Database prepared in advance | No | None |
var | Name of the variable to represent the database | No | Set default |
scope | Scope of the variable to represent the database | No | Page |
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 will vary based on your MySQL or any other database setup. Considering the above parameters, following example uses the 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>
We will use <sql:setDataSource> in subsequent SQL tags.
jsp_standard_tag_library.htm
Advertisements