我正在尝试将数据存储在couchbase中,然后进行获取,但是在jsp页面中从榻榻米中获取存储桶没有获得成功。我正在使用Spring MVC。
这是我用于获取数据的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<br><br><br><br><br><br><br><br>
<div class ="display" align="center">
<form method="post">
<table id="bk_tbl" cellpadding="20px" cellspacing="20px">
<tr>
<th>BOOK NAME </th>
<th>AUTHOR NAME </th>
<th>ADDRESS </th>
<th>CONTACT </th>
</tr>
<%
try{
System.out.println("Hi c...");
/* CouchbaseClient c = ConnectionManager.instance().getClient();
*/
//String n1ql="SELECT * FROM `BOOKS` WHERE META().id LIKE 'bk%'";
Cluster cluster = CouchbaseCluster.create("127.0.0.1");
Bucket bucket = cluster.openBucket("Book", "root123");
String n1ql="select * from `Book`";
N1qlQueryResult result = bucket.query(N1qlQuery.simple(n1ql));
System.out.println("Before row : "+result);
for (N1qlQueryRow row : result) {
System.out.println("After row : ");
System.out.println("row : "+row);
String strJson=row.toString();
System.out.println("strJson : "+strJson);
JSONObject jsonObj = new JSONObject(strJson);
String strBucket = jsonObj.getString("Book");
JSONObject jsonObj1 = new JSONObject(strBucket);
String bk_name = jsonObj1.getString("fname");
String bk_author = jsonObj1.getString("aname");
String bk_address = jsonObj1.getString("address");
String bk_contact = jsonObj1.getString("contact");
%>
<tr>
<td><%=bk_name %></td>
<td><%=bk_author %></td>
<td><%=bk_address %></td>
<td><%=bk_contact %></td>
</tr>
<%
}
System.out.println("Bye c...");
} catch(Exception ex) {
ex.printStackTrace();
}
%>
</table>*emphasized text*
</form>
</div>
</body>
</html>
在这里,我在输出中得到一个空白页。此外,它不会引发任何异常或错误
答案 0 :(得分:0)
我相信您忘记创建主索引:
CREATE PRIMARY INDEX `book-primary-index` ON `Book` USING GSI;
如果主索引已经存在,请检查数据库中是否确实有文档或连接字符串是否正确。