1
2
3
4
5
6
7
8
9
10
11
12package configuration_service;
13
14import java.sql.Connection;
15import java.sql.PreparedStatement;
16import java.sql.ResultSet;
17import java.sql.SQLException;
18
19public class DatabaseConfigurationService implements ConfigurationService, ConnectionAware
20{
21 private Connection _connection;
22
23 public void setConnection(Connection connection)
24 {
25 _connection = connection;
26 }
27
28 public String getConfigurationValue(String key) throws SQLException
29 {
30
31 PreparedStatement statement = _connection.prepareStatement("SELECT value FROM configuration WHERE id = ?");
32 statement.setString(1, key);
33 ResultSet result = statement.executeQuery();
34 result.next();
35 String value = result.getString(1);
36 result.close();
37 statement.close();
38 return value;
39 }
40
41}
// Copyright 2007, Tim Vernum
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package configuration_service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DatabaseConfigurationService implements ConfigurationService, ConnectionAware
{
private Connection _connection;
public void setConnection(Connection connection)
{
_connection = connection;
}
public String getConfigurationValue(String key) throws SQLException
{
// NB: This isn't particularly good JDBC code. Don't copy this!
PreparedStatement statement = _connection.prepareStatement("SELECT value FROM configuration WHERE id = ?");
statement.setString(1, key);
ResultSet result = statement.executeQuery();
result.next();
String value = result.getString(1);
result.close();
statement.close();
return value;
}
}