Retrive Records through PreparedStatement using Oracle JDBC Pool Resource

In this post i will show you to how to select data from database through PreparedStatement using Oracle JDBC Pool Resource. In this example we are selecting all records from Users table and using WHILE LOOP shows all records into browser.

1) Create JSP page using Netbean IDE.

2) Add following classes in your JSP page.

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"% >
<%@page import="java.sql.SQLException"%& >
<%@page import="java.sql.Connection"% >
<%@page import="javax.sql.DataSource"% >
<%@page import="javax.naming.InitialContext"%>

3) Add the following code in body tag. This code contain JDBC Pool Resource connection, plain SQL Statement and PreparedStatement.

InitialContext ctx = new InitialContext();
DataSource ODS = (DataSource) ctx.lookup("jdbc/__oracon");
Connection CN = ODS.getConnection();
if (CN == null)
throw new SQLException("Error establishing connection!");
String query = "SELECT * FROM users";
PreparedStatement statement = CN.prepareStatement(query);
ResultSet RS = statement.executeQuery();
while (
out.print(rs.getString("user_name") + "



Popular posts from this blog

How to create Oracle stored Procedures using TOAD for Oracle

How to Create Packages in Oracle Database using TOAD for Oracle

Create Tables in Oracle Database using TOAD