1 package org.kuali.ole.service.impl;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.service.DataBaseConnectionService;
5 import org.kuali.rice.core.api.config.property.ConfigContext;
6
7 import java.sql.Connection;
8 import java.sql.DriverManager;
9 import java.sql.PreparedStatement;
10 import java.sql.ResultSet;
11
12
13
14
15 public class DataConnectionServiceImpl implements DataBaseConnectionService {
16
17 private static final Logger LOG = Logger.getLogger(DataConnectionServiceImpl.class);
18
19 @Override
20 public ResultSet getResults(String query) {
21 ResultSet resultSet=null;
22 try {
23 PreparedStatement preparedStatement = null;
24 Connection connection = getConnection();
25 preparedStatement = connection.prepareStatement(query);
26 resultSet = preparedStatement.executeQuery();
27
28 }catch (Exception ex){
29 ex.printStackTrace();
30 }
31 return resultSet;
32
33 }
34 public Connection getConnection() {
35 Connection connection = null;
36 try {
37 String connectionUrl = ConfigContext.getCurrentContextConfig().getProperty("datasource.url");
38 String userName = ConfigContext.getCurrentContextConfig().getProperty("datasource.username");
39 String passWord = ConfigContext.getCurrentContextConfig().getProperty("datasource.password");
40 String driverName = ConfigContext.getCurrentContextConfig().getProperty("jdbc.driver");
41 Class.forName(driverName);
42 connection = DriverManager.getConnection(connectionUrl, userName, passWord);
43 } catch (Exception e) {
44
45 }
46 return connection;
47 }
48 }