<Sql: setDataSource> tag
<Sql: setDataSource> tag is used to configure the data source or data source information is stored in a variable scope for other JSTL database operations as a data source.
Syntax
<sql:setDataSource var="<string>" scope="<string>" dataSource="<string>" driver="<string>" url="<string>" user="<string>" password="<string>"/>
Attributes
<Sql: setDataSource> tag has the following attributes:Attributes | description | If necessary | Defaults |
---|---|---|---|
driver | To register a JDBC driver | no | no |
url | JDBC URL database connection | no | no |
user | Database Username | no | no |
password | Database Password | no | no |
dataSource | Pre-prepared database | no | no |
var | Representatives variable database | no | default setting |
scope | Scope var attribute | no | Page |
Examples Demo
Setting MySQL database:
- Use JDBC MySQL driver.
- Connect the machine TEST database.
- Use user_id and mypassword access TEST database.
The above parameters in MySQL or other database is very basic, it is best to remember that the above parameters. Next is a simple to use <sql: setDataSource> tag example:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ 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 use the other labels in the SQL <sql: setDataSource> tag.