Jsp-jstl-sql-setdatasource-tag

提供:Dev Guides
移動先:案内検索

JSTL-SQL <sql:setDataSource>タグ

*<sql:setDataSource>* タグは、データソース構成変数を設定するか、他のJSTLデータベースアクションへの入力として使用できるスコープ変数にデータソース情報を保存します。

属性

*<sql:setDataSource>* タグには次の属性があります-
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

MySQLデータベースのセットアップに関する次の情報を考慮してください-

  • JDBC MySQL ドライバーを使用しています。
  • ローカルマシンのTESTデータベースに接続します。
  • TESTデータベースにアクセスするには、 user_idmypassword を使用します。

上記のすべてのパラメーターは、MySQLまたはその他のデータベース設定によって異なります。 上記のパラメーターを考慮して、次の例では setDataSource タグを使用します-

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

後続のSQLタグで<sql:setDataSource>を使用します。