how to connect the back end with Directive tag in jsp ...

Answer Posted / lovly

A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets.


<%@ page language=”java” contentType=”text/html”
import=”java.sql.*,java.sql.Statement %>

<%
//load the Oracle JDBC driver or any other driver for a specific
vendor
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);

//open a connection to the “scott” database or other database which you have created. You should provide the username and password as part of this connection string. Here the username and password are scott and tiger.
Connection con=
DriverManager.getConnection(”jdbc:odbc:scott”,”scott”,”tiger”);

//create a statement object for sending SQL queries
Statement stmt = con.createStatement();

//place query results in a ResultSet object

//To get all projects of a particular project leader.
ResultSet res = stmt.executeQuery(” select * from employee”);

String ename=null;

%>
Further then you can use the resultset object “res” to read data in the following way.



<%
while(res.next())
{
ename=res.getString(”ename”);
%>

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is session object in jsp?

583


What are the directives in jsp?

458


How to ignore the el expression evaluation in a jsp?

507


What is the use of?

534


Explain the difference between servlet and jsp?

541






How can I prevent the output of my jsp or servlet pages from being cached by the browser?

564


Explain the difference between servletcontext and pagecontext in jsp?

484


What is the difference between jsp and thymeleaf?

509


Which tags are used for bean development?

479


Explain the various scope values for tag.

511


Why do we use expression language in jsp?

465


What are the implicit el objects in jsp?

540


What is expression language injection?

498


Which jsp implicit objects are thread safe?

488


How jsp is compiled?

474