1

I can't manage to get this right. I'm not sure of what is wrong. Apparently the connection is ok but can't get the result back of the query.

package probandoCouch;
import cdata.jdbc.couchbase.CouchbaseDriver;
import java.sql.Statement;
import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class App {
public static void main(String[] args) {

    try {
        Connection conn = DriverManager.getConnection(
                "jdbc:couchbase:User=\"Administrator\";Password=\"Administrator\";Server=\"127.0.0.1\";");
        Statement stat = conn.createStatement();
        boolean ret = stat.execute("SELECT message FROM greeting WHERE author='foo';");
        if (ret) {
            ResultSet rs = stat.getResultSet();
            while (rs.next()) {
                for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                    System.out.println(rs.getMetaData().getColumnName(i) + "=" + rs.getString(i));
                }
            }
        }

    } catch (SQLException e) {
    }
}

}

Saqib Ali
  • 3,953
  • 10
  • 55
  • 100
Calipox20
  • 11
  • 1

1 Answers1

1

Can you please remove semicolon(;) from query and try

SELECT message FROM greeting WHERE author='foo';

Updated Query:

SELECT message FROM greeting WHERE author='foo'

With semicolon jdbc will fail with error

java.sql.SQLException: ORA-00933: SQL command not properly ended

In your code you may print the exception to see if any exception is thrown.

Kousik Mandal
  • 686
  • 1
  • 6
  • 15