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.
Result
1) Create JSP page using Netbean IDE.
2) Add following classes in your JSP page.
3) Add the following code in body tag. This code contain JDBC Pool Resource connection, plain SQL Statement and PreparedStatement.
<%@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"%> |
<% 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 (RS.next()) { out.print(rs.getString("user_name") + " "); } %> |
Result
osb online training
ReplyDeleteoracle scm online training
app v online training
windows admin online training
sap wm online training
sap fico online training