How to Access Data Base from JSP Page?
https://www.computersprofessor.com/2016/06/how-to-access-data-base-from-jsp-page.html?m=0
In general if we want to interact with
the data base from JSP page that we should use scripting elements where we
should provide the required JDBC (Java data base connectivity code.
The
above approach is against for JSP technology that’s why we should go for an
alternative. Here the required was provided by JSP technology in the form of
set of SQL tags as part of JSTL (Java standard jag library). To provide
database interaction from JSP page JSTL has provided the following set of tags.
1. <sql: set data source>
2. <sql: update>
3. <sql:query>
4. <sql: transaction>
5. <sql: param>
To
get data from data base we must do the
following.
® Make the connection
® Load the driver
® Execute sql queries
® Close the connection.
<sql: set data source>:-
This tag will provide the basic JDBC environment like load the driver,
establish the connection and so on.
Syntax:- <sql: set data source driver = “ “ url = “ “ user = “ “ password = “ “ />
All
the above attributes can be used to specify the parameters like driver class,
driver url, database user name and password respectively.
<sql: update>:-
This tag can be used to execute update group
sql queries like create table, insert records, update table, delete table and
so on.
Syntax:- <sql: update sql = “ “ var = “ “/>
where sql attribute can be used to specify update group sql query. ‘var’
attribute can be used to hold the resultant value.
<sql: query>:-
This tag can be used to fetch the data from
dbase by executing selection group sql queries.
Syntax:- <sql: query sql = “ select * from emp” var = “Result”/>
<sql:, transaction>:-
This tag can be used to gather set of
“ and as a unit in order to perform a
unit of work (transaction).
Eg:-
<% @ taglib URL = “http://java.sum.com/JSTL/SQL” prefix = “sql”/>
<sql: set data source driver; “oracle. JDBC.driver. Oracle driver” URL = “Jdbc: oracle: thin: @ local host: 5121 xe” user = “system” password = “sasi”/>
<SQL: update sql: create table emp(eno number, ename varchar 2(20))” var = “ result”/>