Latest web development tutorials

<Sql: setDataSource> tag

Biblioteca JSP Standard Tag Biblioteca JSP Standard Tag

<Sql: setDataSource> tag viene utilizzato per configurare le informazioni di origine di dati o fonte di dati è memorizzato in un ambito variabile per altre operazioni di database JSTL come fonte di dati.

sintassi

<sql:setDataSource
  var="<string>"
  scope="<string>"
  dataSource="<string>"
  driver="<string>"
  url="<string>"
  user="<string>"
  password="<string>"/>

proprietà

<Sql: setDataSource> tag ha i seguenti attributi:

proprietà descrizione Se necessario difetto
autista Per registrare un driver JDBC no no
URL connessione al database JDBC URL no no
utente Database Nome utente no no
password password database no no
dataSource banca dati pre-preparati no no
var Rappresentanti del database variabile no impostazioni predefinite
portata attributo var Scope no pagina


Esempi Demo

Impostazione database MySQL:

  • Utilizzare driver JDBC MySQL.
  • Collegare il database di test della macchina.
  • Utilizzare user_id e mypassword accesso al database TEST.

I parametri di cui sopra in MySQL o di altri database è molto semplice, è meglio ricordare che i parametri di cui sopra. Next è un semplice da usare <sql: setDataSource> Esempio tag:

<%@ 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>

Si utilizzerà le altre etichette nella SQL <sql: setDataSource> tag.


Biblioteca JSP Standard Tag Biblioteca JSP Standard Tag