Professional Documents
Culture Documents
Class.forName("oracle.jdbc.driver.OracleDriver");
3) Connect to database:
where oracle.world is the TNS NAMES entry and root is the username and password.
where localhost is the host,3306 is the port, roseindia is the database and root is the username and
password.
a)create statement:
Statement st = connection.createStatement();
rs.close();
st.close();
connection.close();
Example1:
Example2:
<HTML>
<HEAD><TITLE>Simple JSP/Oracle Query Example</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<B>Employees</B>
<BR><BR>
<%
Connection conn = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@fuju.exzilla.net:1521:fuju",
"scott",
"tiger");
while(rs.next())
{
out.println("<TR>");
out.println(" <TD>" + rs.getString("EMPID") + "</TD>");
out.println(" <TD>" + rs.getString("ENAME") + "</TD>");
out.println(" <TD>" + rs.getString("ESURNAME") + "</TD>");
out.println(" <TD>" + rs.getInt("SALARY") + "</TD>");
out.println(" <TD>" + rs.getString("STARTDATE") + "</TD>");
out.println("</TR>");
}
out.println("</TABLE>");
}
catch(SQLException e)
{
out.println("SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
out.println(e.getMessage() + "<BR>");
}
catch(ClassNotFoundException e)
{
out.println("ClassNotFoundException: " + e.getMessage() + "<BR>");
}
finally
{
//Clean up resources, close the connection.
if(conn != null)
{
try
{
conn.close();
}
catch (Exception ignored) {}
}
}
%>
</CENTER>
</BODY>
</HTML>