我没法做到这一点。我不确定出了什么问题。显然连接正常,但无法返回查询结果。
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) {
}
}
}
您能从查询中删除分号(;(并尝试吗
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
在代码中,您可以打印异常以查看是否引发了任何异常。