Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.
package com.presidentio.testdatagenerator.output;
public abstract class AbstractJdbcSink extends AbstractBufferedSink {
    private Connection connection;
    @Override
    public void init(Map<StringStringprops) {
        String connectionUrl = props.get(.);
        if (connectionUrl == null) {
            throw new IllegalArgumentException("Connection url does not specified");
        }
        String jdbcDriver = props.get(.);
        if (jdbcDriver == null) {
            throw new IllegalArgumentException("Jdbc driver does not specified");
        }
        try {
             = prepareConnection(connectionUrljdbcDriver);
        } catch (SQLException | IOException e) {
            throw new IllegalStateException("");
        }
    }
    @Override
    public void write(String request) {
        try {
            .prepareStatement(request).execute();
        } catch (SQLException e) {
            throw new IllegalStateException("Failed to execute query: " + requeste);
        }
    }
    @Override
    public void close() {
        super.close();
        try {
            .close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    private Connection prepareConnection(String connectionUrlString jdbcDriverthrows SQLExceptionIOException {
        if (jdbcDriver != null) {
            try {
                Class.forName(jdbcDriver);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
        return DriverManager.getConnection(connectionUrl);
    }
New to GrepCode? Check out our FAQ X