[opencms-dev] how connect to database from jsp ?
Steve
steve.welsh at redplanetuk.com
Mon Nov 15 10:56:21 CET 2004
I don't know which container you are running in - but I know that in
Tomcat you can define a database connection as a JNDI resource in
server.xml. You then get connection pooling for free! I believe the
default pooling is DBCP.
Steve,
REDPlanet Technologies Ltd,
Salters House, Salters Lane Ind. Est., Sedgefield, Stockton-on-Tees,
TS21 3EE
www.redplanetuk.com
Tel +44 (1740) 625222
-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Tim Van Der Hulst
Sent: 14 November 2004 20:24
To: The OpenCms mailing list
Subject: RE: [opencms-dev] how connect to database from jsp ?
u can always try using a database API layer ;)
eg http://www.javaranch.com/jenny.jsp
Regards,
TiM
-----Original Message-----
From: Mark [mailto:bef5471 at iperbole.bologna.it]
Sent: Saturday, 13 November 2004 10:54 a.m.
To: opencms-dev at opencms.org
Subject: [opencms-dev] how connect to database from jsp ?
Hi Guys!
Which is the better way to get a connection to the opencms database in
order to
submit a query from a JSP page?
I tested the code below with success, but I suppose it is not the best
way when
multiple connection take place at the same time: a connection taken from
a pool
of pooled connections whould be more performant. Can someone rewrite the
code
below in a more correct way?
Thank's in advance,
I'm new here and I do apologize for my incert English (I'm Italian).
Marco.
<%@ page import =
"java.sql.Connection,java.sql.DriverManager,java.sql.SQLException,
java.sql.Statement, java.sql.ResultSet,
java.util.*,java.io.*"
%>
<%
Connection myconn;
String DbDriver = "org.gjt.mm.mysql.Driver";
String DbConStr = "jdbc:mysql://localhost:3306/opencms";
String DbUser ="user";
String DbPwd ="pwd";
try {
Class.forName(DbDriver);
myconn = DriverManager.getConnection(DbConStr, DbUser,
DbPwd);
Statement mystat = myconn.createStatement();
ResultSet rs = mystat.executeQuery("SELECT name,years FROM
people");
while (rs.next()) {
String s = rs.getString("name");
int n = rs.getInt("years");
out.println(s+"<b>"+n+"</b>");
}
myconn.close();
} catch (SQLException e) {
out.println("<p>Exception</p>");
} catch (ClassNotFoundException e) {
out.println("<p>Exception</p>");
}
%>
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please
visit
http://mail.opencms.org/mailman/listinfo/opencms-dev
##
##
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please
visit
http://mail.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list