<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">JSTL setDataSource Tag provides capability to create a datasource directly from JSP and it can be stored in a variable to use later with the help of scope attribute.</p>
<p>Syntax-<br />
<i><;sql:setDataSource</p>
<p> ; var=&#8221;<;string>;&#8221;</p>
<p> ; scope=&#8221;<;string>;&#8221;</p>
<p> ; dataSource=&#8221;<;string>;&#8221;</p>
<p> ; driver=&#8221;<;string>;&#8221;</p>
<p> ; url=&#8221;<;string>;&#8221;</p>
<p> ; user=&#8221;<;string>;&#8221;</p>
<p> ; password=&#8221;<;string>;&#8221;/>;</i></p>
<p> <b>JSP <i><;sql:setDataSource>; </i>Tag has following attributes.</b></p>
<p> <b>1. driver Attribute:</b> Specifies the driver to connect database. For each database there is a separate driver. In this example, we are connecting to MySQL database and hence driver is com.mysql.jdbc.Driver</p>
<p> <b>2. url Attribute:</b> Specifies the location of the database.</p>
<p> <b>3. var Attribute:</b> Specifies the variable which holds the dataSource once it is created.</p>
<p> <b>4. user Attribute:</b> Specifies the user you already created to access database.</p>
<p> <b>5. password Attribute: </b>Specifies the password for the user you already assigned to access database.</p>
<p> <b>JSP <i>setDataSource </i>Example:</b></p>
<p> Consider the following information about your MySQL database setup:</p>
<ul style="text-align: left;">
<li>We are using JDBC MySQL driver.</li>
<li>We are going to connect to TEST database on local machine.</li>
<li>We would use user_id and mypassword to access TEST database.</li>
</ul>
<p>
 All the above parameters would vary based on your MySQL or any other database setup. Keeping above parameters in mind, following is a simple example to use <b><i>setDataSource </i></b>tag:</p>
<pre class="highlight" name="code"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>;
<;%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>;

<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
 "http://www.w3.org/TR/html4/loose.dtd">;
<;html>;
<;head>;
<;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">;
<;title>;JSTL SQL Tags - setDataSource Example<;/title>;
<;/head>;
<;body>;

 <;sql:setDataSource driver="com.mysql.jdbc.Driver"
 url="jdbc:mysql://localhost:3306/database_name"
 var="localSource" 
 user="database_user" 
 password="database_password"/>;

 <;sql:query dataSource="${localSource}" 
 sql="SELECT * FROM employee WHERE salary >; 10000" 
 var="result" />;
 
<;/body>;
<;/html>;
</pre>
<p>
As shown above <i><b>setDataSource </b></i>Tag set data source in a variable <b><i>localSource</i></b>. Using this data source, you can do SQL operations directly from JSP.</p>
<p>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/2013/10/jstl-format-tag-example.html">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/2013/10/jsp-standard-tag-library-jstl-tutorial.html">Index </a>||  ; >;>;<a href="https://dineshonjava.com/2013/10/jstl-sql-query-tag-example.html">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jstl-format-tag-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/jstl-sql-query-tag-example/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '298'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…