Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

code for JSP JDBC  RSS feed

Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I need some sample code for JSP and JDBC. i.e JDBC code written in java class and we are using that class in our jsp page.
meaning to say , I want to see some samle codes in which presentation and buisness logic are isolated.
Can anybody pls help ?
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using DAO's or Data Access Objects to deal with a MySQL database and JSP's.
In the DAO I write :
(PS the extension of GeneralDao is needed because I only define once which
JDBC driver I'm using to getConnection() )
public class LandDao extends GeneralDao {
// operations
* Geeft alle actieve landen weer
* @return Collection
* @param _ID
public ArrayList zoekLand()
throws SQLException
ArrayList landLijst = new ArrayList();
StringBuffer zoekString = new StringBuffer();
zoekString.append("select * from land");
Connection con = null;
/* initialisatie is nodig om compilatie
fout te vermijden */
PreparedStatement ps = null;
ResultSet rs = null ;

try {
System.out.println("opzoeken van alle landen");
con = getConnection();
ps = con.prepareStatement(zoekString.toString());
rs = ps.executeQuery();
while (
Land land = new Land(rs);
System.out.println("landlijst is opgebouwd");
} catch (SQLException SQLEx)
throw SQLEx;

return landLijst ;
} // end zoekLand
ANd LandLijst is defined as a Java Bean inside the JSP :
<%@ page import = "org.brukkerlin.adres.Land" %>
<%@ page import = "java.util.Iterator" %>
<jsp:useBean id="servletPath" class="java.lang.String" scope="request"/>
<jsp:useBean id="landLijst" class="java.util.ArrayList" scope="session"/>
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!