Simple JSP JDBC Example

January 29, 2008

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:
  1. <%@ page import="java.sql.*" %>
  2. <%
  3. try
  4. {
  5.     //this is how you might get a POST or GET variable from the request to use
  6.     //String user_id = request.getParameter("some_var");
  7.  
  8.     Connection  conn = DriverManager.getConnection("jdbc:oracle:thin:@HOSTNAME:PORT:SID","USERNAME","PASSWORD");
  9.     Statement stmt = conn.createStatement();
  10.     ResultSet rset = stmt.executeQuery("SELECT sysdate FROM dual'");
  11.     if (rset.next())
  12.     {
  13.         out.println(rset.getString(1));
  14.     }
  15.     else
  16.     {
  17.         out.println("No records found");
  18.     }
  19.     rset.close();
  20.     stmt.close();
  21. }
  22. catch (SQLException e) {
  23.     out.println("Exception");
  24. }
  25. %>

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: , , , , , , , , , , ,

Related:


Comments

Got something to say?





User contributed tags: jsp examples (21) - t (17) - jsp jdbc (16) - IN (14) - simple jsp example (14) - jsp-jdbc examples (10) - simple jsp examples (10) - jsp example (9) - sample jsp (9) - jsp jdbc example (8) - jsp oracle example (8) - mss (7) - jdbc example (5) - PH (4) - jsp sample (4) - jsp jdbc sample (4) - simple JSP (3) - example in jsp (3) - jdbc in jsp with example (3) - simple jsp with jdbc (3) - jdbc examples (3) - JDBC sample program (2) - f (2) - JSP jdbc tags (2) - jdbc y jsp (2) - example with jsp (2) - jsp jdbc simple (2) - jsp example on oracle (2) - jsp sample examples (2) - JDBC simple example (2) - example for jdbc connection (2) - jdbc search example (2) - simple jsp program (2) - Simple jsp with simple oracle jdbc connection (2) - jsp with examples (2) - jdbc sample example (2) - select * from jdbc example (1) - jdbc and jsp example (1) - jdbc sample (1) - jdbc (1) - jsp jdbc oracle example (1) - simple jsp examples with jdbc (1) - http://www google com/ (1) - simple jdbc example (1) - class connection JSP example (1) - nosheep net (1) - jsp jdbc codes (1) - simple jsp mysql example (1) - simple programme of jdbc (1) - Sample JSP JDBC Programs (1) - JSP examples with JDBC (1) - jsp post simple example (1) - http://www google com/ig (1) - simplest jsp program (1) - jsp with jdbc examples (1) - jdbc examples in jsp (1) - a simple JSP script (1) - simple jsp jdbc page (1) - required simple JSP programs (1) - jdbc in jsp examples (1) - jdbc jsp (1) - simple jsp jdbc (1) - simple examples for jdbc (1) - jdbc and jsp (1) - mysql jsp example (1) - how to write jdbc program in jsp (1) - example jsp jdbc connection (1) - oracle jsp driver jdbc (1) - simple jsp script (1) - simple jsp sample (1) - sample jsp websites (1) - java jsp jdbc example (1) - http://www google com/ig?hl=en (1) - 9 (1) - jsp sample codes (1) - jsp and sql simple example (1) - jsp samples (1) - jsp mysql simple example (1) - JSP JDBC example code (1) - jsp for examples (1) - JDBC JSP example (1) - simple jdbc with jsp example (1) - oracle jsp examples (1) - sample jdbc program in JSP (1) - java jsp example oracle resultset (1) - JDBC SIMPLE EXAMPLES (1) - jsp oracle sample (1) - jdbc samples in jsp (1) - jdbc 4 examples (1) - warcraft dota guide item (1) - Sample JSP code (1) - M3 DS Simply buy (1) - JSP with JDBC sample (1) - JSP sample programs (1) - JSP example program (1) - jsp simple example (1) - JSP examples JDBC (1) - JSP examples using JDBC oracle connections (1) - jsp/jdbc examples (1) - sample jsp program with jdbc (1) - jsp jdbc simple example (1) - example no (1) - oracle jdbc simple sample (1) - jsp simple blog example (1) - jdbc programs in jsp (1) - jsp connection example (1) - dota all stars tactics (1) - jsp sample website (1) - sample jdbc code in jsp (1) - CN (1) - jsp thin connection scripts example (1) - examples for jsp jdbc connection (1) - simple examples on jsp (1) - a simple jsp program example (1) - JSP and JDBC examples (1) - jsp by example (1) - JDBCExample (1) - simple jsp scripts (1) - simple jsp code (1) - sample jsp JDBC connectivity (1) - simple jdbc jsp (1) - TW (1) - jdbc with an example (1) - jsp and JDBC and samples (1) - jsp jdbc programme (1) - basic java with pragramme with example (1) - sample jsp for jdbc (1) - simple jdbc code (1) - jdbc simple (1) - simple jsp and jdbc (1) - jsp jdbc code (1) - jsp jdbc connection (1) - jsp jdbc oracle (1) - code for jsp jdbc (1) - sql JSP example (1) - examples in jsp (1) - how to write a simple JSP (1) - jsp example on JDBC (1) - simple jsp form example (1) -