package vu.de.npolke.myexpenses.services.connections;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Copyright 2015 Niklas Polke
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 * @author Niklas Polke
 */
public class JdbcConnector {
	public static final String DATABASE = "D:\\Git Repositories\\MyExpenses\\myexpenses_hsqldb";
	public static final String DRIVER = "org.hsqldb.jdbc.JDBCDriver";
	public static final String URL_PREFIX = "jdbc:hsqldb:file:";
	public static final String URL_SUFFIX = ";user=SA;shutdown=true;hsqldb.lock_file=false";

	static {
		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		Connection connection = null;
		try {
			connection = DriverManager.getConnection(URL_PREFIX + DATABASE + URL_SUFFIX);
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		}
		return connection;
	}
}

@@ -96,51 +96,123 @@
 sql.
-DriverManager;%0Aimport java.sql.SQLException
+SQLException;%0A%0Aimport javax.naming.InitialContext;%0Aimport javax.naming.NamingException;%0Aimport javax.sql.DataSource
 ;%0A%0A/
@@ -895,50 +895,22 @@
 DATA
-BAS
+SOUR
 E = %22
-D:%5C%5CGit Repositories%5C%5CMyExpenses%5C%5C
+jdbc/
 myex
@@ -919,13 +919,9 @@
 nses
-_hsql
+-
 db%22;
@@ -953,124 +953,58 @@
 ing 
-DRIVER = %22org.hsqldb.jdbc.JDBCDriver%22;%0A%09public static final String URL_PREFIX = %22jdbc:hsqldb:file:
+JNDI_PREFIX = %22java:/comp/env/
 %22;%0A
+%0A
 %09p
-ublic
+rivate
  static 
 fina
@@ -1003,125 +1003,167 @@
 tic 
-final String URL_SUFFIX = %22;user=SA;shutdown=true;hsqldb.lock_file=false%22;%0A%0A%09static %7B%0A%09%09try %7B%0A%09%09%09Class.forName(DRIVER
+DataSource datasource;%0A%0A%09static %7B%0A%09%09try %7B%0A%09%09%09InitialContext context = new InitialContext();%0A%09%09%09datasource = (DataSource) context.lookup(JNDI_PREFIX + DATASOURE
 );%0A%09
@@ -1176,21 +1176,14 @@
 ch (
-ClassNotFound
+Naming
 Exce
@@ -1329,21 +1329,18 @@
 n = 
-DriverManager
+datasource
 .get
@@ -1354,42 +1354,8 @@
 ion(
-URL_PREFIX + DATABASE + URL_SUFFIX
 );%0A%09

Fix database connection in JdbcConnector with jndi lookup