JSP connection to oracle 10g database
920633Feb 28 2012 — edited Feb 29 2012Hello everyone! I want to connect and retrieve some data from a database. I am using Apache Tomcat and JSP page to so. The user name is SYSTEM, and password is "bmwm5tt"
So I have the following code (below). But I am getting an exception: Exception : oracle.jdbc.driver.OracleDriver
Do I actually have to install the driver? Or maybe the error is in the code? Many thanks!!!
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Simple JSP/Oracle Query Example</TITLE>
</HEAD>
<BODY>
<%
Connection connection = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "bmwm5tt");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Capacity FROM Engine");
while (resultSet.next())
{
int x = resultSet.getInt("Capacity");
}
}
catch(Exception exception)
{
out.println("Exception : " + exception.getMessage() + "");
}
finally
{
if(connection != null)
{
try
{
connection.close();
}
catch (Exception ignored)
{
// ignore
}
}
}
%>
</BODY>
</HTML>