Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSP connection to oracle 10g database

920633Feb 28 2012 — edited Feb 29 2012
Hello 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>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2012
Added on Feb 28 2012
2 comments
10,336 views