Simple JSP JDBC Example
January 29, 2008 | Leave a Comment
I learned to program on Java, but have done little to exercise those skills in the last six years, preferring to leverage PHPs simplicity whenever possible. So... when I had a need to put together a simple JSP script that queried Oracle, I found myself scouring for a truly simple example to start from. Here's the example I put together:
JAVA:
-
<%@ page import="java.sql.*" %>
-
<%
-
try
-
{
-
//this is how you might get a POST or GET variable from the request to use
-
//String user_id = request.getParameter("some_var");
-
-
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@HOSTNAME:PORT:SID","USERNAME","PASSWORD");
-
if (rset.next())
-
{
-
out.println(rset.getString(1));
-
}
-
else
-
{
-
out.println("No records found");
-
}
-
rset.close();
-
stmt.close();
-
}
-
out.println("Exception");
-
}
-
%>
Certainly for your own purposes you would need to write a lot more code than this. Yet, if you seek a simple example just to gain your bearings, this should do it.
Tags: code, driver, java, jdbc, jsp, oracle, oracle thin, programming, query, sql, thin, web
