[opencms-dev] how connect to database from jsp ?

Tim Van Der Hulst Tim.VanDerHulst at waidc.govt.nz
Sun Nov 14 21:24:07 CET 2004


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
##
##



More information about the opencms-dev mailing list