CData JDBC Couchbase Java应用连接问题

huangapple go评论68阅读模式
英文:

CData JDBC Couchbase Java app connection problem

问题

我无法正确处理这个问题我不确定哪里出错了显然连接是正常的但无法获得查询的结果

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) {
        }
    }
}
英文:

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(
				&quot;jdbc:couchbase:User=\&quot;Administrator\&quot;;Password=\&quot;Administrator\&quot;;Server=\&quot;127.0.0.1\&quot;;&quot;);
		Statement stat = conn.createStatement();
		boolean ret = stat.execute(&quot;SELECT message FROM greeting WHERE author=&#39;foo&#39;;&quot;);
		if (ret) {
			ResultSet rs = stat.getResultSet();
			while (rs.next()) {
				for (int i = 1; i &lt;= rs.getMetaData().getColumnCount(); i++) {
					System.out.println(rs.getMetaData().getColumnName(i) + &quot;=&quot; + rs.getString(i));
				}
			}
		}

	} catch (SQLException e) {
	}
}

}

答案1

得分: 1

可以请您从查询中删除分号(;)并尝试

SELECT message FROM greeting WHERE author='foo'

更新后的查询:

SELECT message FROM greeting WHERE author='foo'

带有分号的情况下,jdbc将因错误而失败

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

在您的代码中,您可以打印异常以查看是否抛出了任何异常。

英文:

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

SELECT message FROM greeting WHERE author=&#39;foo&#39;;

Updated Query:

SELECT message FROM greeting WHERE author=&#39;foo&#39;

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.

huangapple
  • 本文由 发表于 2020年9月17日 21:14:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63938851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定