01: //The Salmon Open Framework for Internet Applications (SOFIA)
02: //Copyright (C) 1999 - 2002, Salmon LLC
03: //
04: //This program is free software; you can redistribute it and/or
05: //modify it under the terms of the GNU General Public License version 2
06: //as published by the Free Software Foundation;
07: //
08: //This program is distributed in the hope that it will be useful,
09: //but WITHOUT ANY WARRANTY; without even the implied warranty of
10: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: //GNU General Public License for more details.
12: //
13: //You should have received a copy of the GNU General Public License
14: //along with this program; if not, write to the Free Software
15: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: //
17: //For more information please visit http://www.salmonllc.com
18:
19: package com.salmonllc.examples.example12;
20:
21: import com.salmonllc.jsp.*;
22: import com.salmonllc.html.events.*;
23: import com.salmonllc.sql.DBConnection;
24: import com.salmonllc.util.MessageLog;
25:
26: import java.sql.*;
27:
28: public class JDBCExampleController extends JspController implements
29: SubmitListener {
30:
31: public com.salmonllc.html.HtmlSubmitButton _submit1;
32: public com.salmonllc.html.HtmlText _count;
33:
34: public void initialize() {
35: _submit1.addSubmitListener(this );
36: }
37:
38: public boolean submitPerformed(SubmitEvent e) throws Exception {
39: DBConnection conn = null;
40: try {
41: conn = DBConnection.getConnection(getApplicationName());
42: Statement st = conn.createStatement();
43: ResultSet r = st
44: .executeQuery("select count(*) from examples");
45: if (r.next()) {
46: _count.setVisible(true);
47: _count.setText("Number of Examples=" + r.getInt(1));
48: }
49: r.close();
50: st.close();
51: } catch (SQLException ex) {
52: MessageLog
53: .writeErrorMessage(
54: "Error getting count from examples table",
55: ex, this );
56: } finally {
57: if (conn != null)
58: conn.freeConnection();
59: }
60: return true;
61: }
62:
63: }
|