English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The <sql:setDataSource> tag is used to configure the data source or store data source information in a variable within a scope, which is used as the data source for other JSTL database operations.
<sql:setDataSource var="<string>" scope="<string>" dataSource="<string>" driver="<string>" url="<string>" user="<string>" password="<string>"/>
Attribute | Description | Is it necessary | Default value |
---|---|---|---|
driver | The JDBC driver to register | No | None |
url | The JDBC URL for the database connection | No | None |
user | Database username | No | None |
password | Database password | No | None |
dataSource | Prepared database | No | None |
var | Representing database variables | No | Default settings |
scope | The scope of the var attribute | No | Page |
These parameters are very basic in MySQL or other databases, and it is best to remember the above parameters. Next, an example of using the <sql:setDataSource> tag is given:
<%@ 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 this in other SQL tags <sql:setDataSource> Tags.