Issues with JDBC Connection - Connection has been closed.

Hello,

 

I want to connect with a Java app to a Vertica db to query some data. While I want to execute SQL commands I get the error '[Vertica][JDBC](10060) Connection has been closed.'

The connection was already initialized using the Vertica driver (com.vertica.jdbc.Driver).

 

I debugged the code and I get a Class File Error saying:

'The source attachment does not contain the source for the file JDBCMessageKey.class'

 

When I control the path in this dialog I can see that it really points to the correct project I'm currently working on and to the correct vertica jdbc jar.

 

The IDE I'm using is Eclipse Neon and this is my setting:

 

Mac OSX 10.10.5

Vertica v7.2.0-1

JDK 1.8.0_101

Vertica JDBC 7.2.3.0

 

To exclude any other possible causes I set up the a copy of this project which uses a MySQL driver to connect to a MySQL DB. This works.

 

Thanks

Felix

Comments

  • Nimmi_guptaNimmi_gupta - Select Field - Employee

    Can you share sample of the code and query you are trying to acess through JDBC?

     

    Also  make sure you are pointing to right JDBC driver from eclipse. 

     

    On server side, vertica.log should capture some info about closed connection. Did you check?

     

    -Nimmi

  • Hello Nimmi,

     

    thanks for your reply. My application uses jFames and to post the whole code would be hard to read for you. That's why I created a new project and narrowed the code just to the single point where I got the issue. Then it magically worked. :)

     

    I'm sorry that I did not try it in advance, before posting here, but to me it really looked like a JDBC library issue.

     

    I will try to rewrite my application on top of the new test project. If I still have the issue at some point, I will post it here.

     

    Thanks

    Felix

     

    PS: If some wants to see how I did it, here is my simple test code.

     

     

    public class Main {  
    public static void main(String[] args) {
    VerticaAccess dao = new VerticaAccess();
    dao.getVerticaData();
    }
    }

     

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    public class VerticaAccess {
    private Connection connection = null;
    private Statement statement = null;
    private ResultSet resultSet = null;

    public void getVerticaData(){
    try{
    Class.forName("com.vertica.jdbc.Driver");
    connection = DriverManager
    .getConnection("jdbc:vertica://111.111.111.111:5433/aRandomDBName?"
    + "user=Felix&password=notMyRealPW&ConnectionLoadBalance=true");
    statement = connection.createStatement();
    resultSet = statement.executeQuery("SELECT DISTINCT i.value FROM my_schema.item AS i;");

    while (resultSet.next()) {
    System.out.println( resultSet.getString("value") );
    }

    } catch( Exception e){
    e.printStackTrace();
    }
    }
    }

    A little screenshot of my library refference is attached

     

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file