java - 使用 spring mvc 进行 Couchbase crud 操作
问题描述
我正在尝试将数据存储在 couchbase 中,然后获取它,但我没有成功从 jsp 页面中的 couchbase 获取存储桶。我正在使用弹簧 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>
在这里,我在输出中得到一个空白页。此外,它不会引发任何类型的异常或错误
解决方案
我相信您忘记创建主索引:
CREATE PRIMARY INDEX `book-primary-index` ON `Book` USING GSI;
如果您的主索引已经存在,请检查您的数据库中是否真的有文档或者连接字符串是否正确。
推荐阅读
- python - Pygame 窗口有时会冻结
- php - 在 opencart:2.3.0.2 的注册页面上删除地址 1
- dialogflow-es - Google Dialogflow 是否提供匈牙利语版本?
- java - 一行有 3 个值的列表视图
- sql - 如何使用 Power Query M 将 Excel 表列值拉入 SQL WHERE 子句?
- java - 使用功能将 jts 转换为 GeoJSON 的类型错误
- django - 如何在 Django 和 Redux 中使用 JWT
- python - 熊猫找不到列,ValueError
- flutter - 颤振将3d点转换为2d点
- haskell - 如何重构 Haskell 数据类型中的重复字段名称?