package fr.inria.anhalytics.commons.dao;

import fr.inria.anhalytics.commons.exceptions.PropertyException;
import fr.inria.anhalytics.commons.exceptions.ServiceException;
import fr.inria.anhalytics.commons.properties.CommonsProperties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author azhar
 */
public class DatabaseConnection {

    private static final Logger logger = LoggerFactory.getLogger(DatabaseConnection.class);
    private static Connection connectDB;
    private static Connection connectBiblioDB;
    
    public static Connection getDBInstance() {
        try {
            if (connectDB == null ) {

                connectDB = DriverManager.getConnection("jdbc:mysql://"+CommonsProperties.getMysql_host() +
                (CommonsProperties.getMysql_port().isEmpty() ? "":":" + CommonsProperties.getMysql_port())+"/"+ CommonsProperties.getMysql_db(), CommonsProperties.getMysql_user(), CommonsProperties.getMysql_pass());

            }
        } catch (SQLException e) {
            throw new ServiceException("Can't connect to MySQL. ", e);
        }
        return connectDB;
    }
    
    public static Connection getBiblioDBInstance() {
        try {
            if (connectBiblioDB == null ) {

                connectBiblioDB = DriverManager.getConnection("jdbc:mysql://"+CommonsProperties.getMysql_host() +
                (CommonsProperties.getMysql_port().isEmpty() ? "":":" + CommonsProperties.getMysql_port())+"/"+ CommonsProperties.getMysql_bibliodb(), CommonsProperties.getMysql_user(), CommonsProperties.getMysql_pass());

            }
        } catch (SQLException e) {
            throw new ServiceException("Can't connect to MySQL. ", e);
        }
        return connectBiblioDB;
    }
    
}

@@ -39,73 +39,8 @@
 o;%0A%0A
-import fr.inria.anhalytics.commons.exceptions.PropertyException;%0A
 impo
@@ -164,16 +164,74 @@
 erties;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import j
@@ -314,74 +314,14 @@
 ion;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A
- *%0A
  * @
@@ -552,20 +552,16 @@
 blioDB;%0A
-    
 %0A    pub
@@ -639,33 +639,32 @@
 onnectDB == null
- 
 ) %7B%0A%0A           
@@ -672,210 +672,278 @@
     
-connectDB = DriverManager.getConnection(%22jdbc:mysql://%22+CommonsProperties.getMysql_host() +%0A                (CommonsProperties.getMysql_port().isEmpty() ? %22%22:%22:%22 + CommonsProperties.getMysql_port())+
+final String mysqlPort = CommonsProperties.getMysql_port().isEmpty() ? %22%22 : %22:%22 + CommonsProperties.getMysql_port();%0A                final String url = %22jdbc:mysql://%22%0A                        + CommonsProperties.getMysql_host() +%0A                        mysqlPort + 
 %22/%22
+ 
 + Co
@@ -967,24 +967,114 @@
 etMysql_db()
+ + %22?characterEncoding=utf8%22;%0A%0A                connectDB = DriverManager.getConnection(url
 , CommonsPro
@@ -1126,33 +1126,32 @@
 tMysql_pass());%0A
-%0A
             %7D%0A  
@@ -1296,20 +1296,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -1403,17 +1403,16 @@
  == null
- 
 ) %7B%0A%0A   
@@ -1428,216 +1428,278 @@
     
-connectBiblioDB = DriverManager.getConnection(%22jdbc:mysql://%22+CommonsProperties.getMysql_host() +%0A                (CommonsProperties.getMysql_port().isEmpty() ? %22%22:%22:%22 + CommonsProperties.getMysql_port())+
+final String mysqlPort = CommonsProperties.getMysql_port().isEmpty() ? %22%22 : %22:%22 + CommonsProperties.getMysql_port();%0A                final String url = %22jdbc:mysql://%22%0A                        + CommonsProperties.getMysql_host() +%0A                        mysqlPort + 
 %22/%22
+ 
 + Co
@@ -1737,78 +1737,104 @@
 db()
-, CommonsProperties.getMysql_user(), CommonsProperties.getMysql_pass()
+ + %22?characterEncoding=utf8%22;%0A%0A                connectBiblioDB = DriverManager.getConnection(url
 );%0A%0A
@@ -2001,15 +2001,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

Fix #68 http://stackoverflow.com/questions/3040597/jdbc-character-encoding