英文:
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(
"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) {
}
}
}
答案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='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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论