BD jsp jsp and eclipse IDE
well this is the connection that corresponds to the J2SE platform and is the easiest
, but it is the most recommended for j2ee, since
for many simultaneous connections, performs very slow
but could be improved with a design pattern as a singleton
, generally implemented as a desktop application in java
, the idea would occupy propierdades
we provide the web container, which we can provide a connection
pool type. (How a connection pool
explain it in a previous article)
for an application of a few connections 3, 5 or 7
the following example I think that may be good, and most importantly
does not have a major impact of moving from J2SE to J2EE.
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
html
head / head body
postgres connection h1 / h1
<%
try {String connectionURL = "jdbc: postgresql: / / localhost / example";
Connection connection = null;
Class.forName ("org.postgresql.Driver"). newInstance ();
connection = DriverManager.getConnection (connectionURL, "postgres", "1234");
connection.createStatement
Statement stat = ();
unsql String = "select * from company" ResultSet
stat.executeQuery response = (unsql)
while (respuesta.next ()) {
out.println ("" + respuesta.getString ("name"));}
respuesta.close ();
stat.close ();
Connection.Close ();
} catch (Exception e) {
out.println ("/ database connection error");}
%>
/ body / html
eye I have no tags with <> to keep me from
problem
blog can be seen that the connection is the same deal in
J2SE, but do not worry, because in a previous article
explain how to generate a pool in a servlet, but now in the following article explain how
do it in a jsp (I think I have an example
JSTL, JSTL technology but is not my favorite, I'd rather JSF, Struts and Spring) a contribution to java
0 comments:
Post a Comment