Search in sources :

Example 1 with MySQLSingleConnection

use of net.idea.modbcum.c.MySQLSingleConnection in project ambit-mirror by ideaconsult.

the class Context method getConnection.

protected DBConnectionConfigurable<Context> getConnection(String configFile) throws SQLException, AmbitException {
    try {
        Context context = initContext();
        String driver = context.get(Preferences.DRIVERNAME);
        if ((driver != null) && (driver.contains("mysql")))
            return new MySQLSingleConnection(context, configFile);
        else
            throw new AmbitException("Driver not supported");
    } catch (Exception x) {
        x.printStackTrace();
        throw new AmbitException(x);
    }
}
Also used : MySQLSingleConnection(net.idea.modbcum.c.MySQLSingleConnection) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CommunicationsException(com.mysql.jdbc.CommunicationsException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with MySQLSingleConnection

use of net.idea.modbcum.c.MySQLSingleConnection in project ambit-mirror by ideaconsult.

the class Context method getConnection.

protected DBConnectionConfigurable<Context> getConnection(String configFile) throws SQLException, AmbitException {
    try {
        Context context = initContext();
        String driver = context.get(Preferences.DRIVERNAME);
        if ((driver != null) && (driver.contains("mysql"))) {
            MySQLSingleConnection<Context> mc = new MySQLSingleConnection<Context>(context, configFile) {

                @Override
                protected void configurefromContext(LoginInfo li, Context context) {
                    if (context.get(Preferences.DATABASE) != null)
                        li.setDatabase(context.get(Preferences.DATABASE));
                    if (context.get(Preferences.USER) != null)
                        li.setUser(context.get(Preferences.USER));
                    if (context.get(Preferences.PASSWORD) != null)
                        li.setPassword(context.get(Preferences.PASSWORD));
                    if (context.get(Preferences.HOST) != null)
                        li.setHostname(context.get(Preferences.HOST));
                    if (context.get(Preferences.PORT) != null)
                        li.setPort(context.get(Preferences.PORT));
                    if (context.get(Preferences.DRIVERNAME) != null)
                        li.setDriverClassName(context.get(Preferences.DRIVERNAME));
                }

                @Override
                protected Logger getLogger() {
                    return logger_cli;
                }
            };
            return mc;
        } else
            throw new AmbitException("Driver not supported");
    } catch (AmbitException x) {
        throw x;
    } catch (Exception x) {
        throw new AmbitException(x);
    }
}
Also used : LoginInfo(net.idea.modbcum.i.LoginInfo) MySQLSingleConnection(net.idea.modbcum.c.MySQLSingleConnection) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with MySQLSingleConnection

use of net.idea.modbcum.c.MySQLSingleConnection in project ambit-mirror by ideaconsult.

the class Context method getConnection.

protected DBConnectionConfigurable<Context> getConnection(File configFile) throws SQLException, AmbitException {
    try {
        Context context = initContext();
        String driver = context.get(Preferences.DRIVERNAME);
        if ((driver != null) && (driver.contains("mysql")))
            return new MySQLSingleConnection(context, configFile);
        else
            throw new AmbitException("Driver not supported");
    } catch (Exception x) {
        x.printStackTrace();
        throw new AmbitException(x);
    }
}
Also used : MySQLSingleConnection(net.idea.modbcum.c.MySQLSingleConnection) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CommunicationsException(com.mysql.jdbc.CommunicationsException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ConnectException (java.net.ConnectException)3 SQLException (java.sql.SQLException)3 MySQLSingleConnection (net.idea.modbcum.c.MySQLSingleConnection)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 CommunicationsException (com.mysql.jdbc.CommunicationsException)2 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1 LoginInfo (net.idea.modbcum.i.LoginInfo)1