KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > isac > plugins > jdbcsimple10 > actions > JDBCSample


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF
20 *
21 * Contact: clif@objectweb.org
22 */

23 package org.objectweb.clif.isac.plugins.jdbcsimple10.actions;
24
25 import java.sql.Connection JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.sql.Statement JavaDoc;
29 import java.util.Hashtable JavaDoc;
30
31 import org.objectweb.clif.isac.plugins.jdbcsimple10.SessionObject;
32 import org.objectweb.clif.storage.api.ActionEvent;
33
34 /**
35  * This static class implements sample methods for isac jdbc plugin
36  *
37  * @author JC Meillaud
38  * @author A Peyrard
39  */

40 public class JDBCSample {
41
42     /**
43      * This method execute a request on a sql base
44      * @param so The session object which store some datas
45      * @param params in params we expect a request to be performed, the key for this value
46      * will be 'sql_request'
47      * @param report The report of the action which will be completed
48      * @return The report of the action
49      */

50     public static ActionEvent sqlRequest(SessionObject so, Hashtable JavaDoc params, ActionEvent report) {
51         // get the sql connection
52
Connection JavaDoc connection = so.getConnection() ;
53         // get the sql request
54
String JavaDoc request = (String JavaDoc)params.get("sql_request") ;
55         // set the report for this action
56
report.type = "JDBC_sql_request" ;
57         // init a new result set to store the result of the request
58
ResultSet JavaDoc rs = null;
59         try {
60             report.setDate(System.currentTimeMillis()) ;
61             Statement JavaDoc stmt = connection.createStatement();
62             rs = stmt.executeQuery(request);
63             report.successful = true ;
64         }
65         catch (SQLException JavaDoc se) {
66             report.comment = "Unable to execute the request "+se;
67             report.successful = false ;
68         }
69         finally {
70             report.duration = (int)(System.currentTimeMillis() - report.getDate());
71         }
72         return report ;
73     }
74
75 }
76
Popular Tags