gpt4 book ai didi

java - 用空值填充文本框

转载 作者:行者123 更新时间:2023-12-01 18:06:38 26 4
gpt4 key购买 nike

我正在编写一个 Web 应用程序,其中的数据必须从数据库中提取并显示在文本框中。一切正常。但我需要在这些文本框中将值显示为“无可用数据”if(!rs.next()),目前我正在尝试以下代码。

package org.DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.bean.UserBean;
import org.code.general.DBConnection;
import org.code.general.GetTheUserDetails;

public class GetDataDAO {
DBConnection dbConnection = new DBConnection();
GetTheUserDetails getTheUserDetails = new GetTheUserDetails();

public List<UserBean> list(String systemUserName) throws Exception {

List<UserBean> userBeans = new ArrayList<UserBean>();
try {

Connection conn = dbConnection.getConn();
Statement stmt = dbConnection.getStmt();
ResultSet rs = dbConnection.getRs();
String excelPath = dbConnection.getExcelPath();
String queryString = null;
dbConnection.createClassForNameForExcel();
conn = DriverManager.getConnection(
"jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + excelPath + "; READONLY=FALSE;");
System.out.println("Connecting to database…");
System.out.println("Oracle JDBC Driver Registered!");
if (conn != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
stmt = conn.createStatement();
queryString = "Select * from [" + dbConnection.getSheetPath()
+ "$] where STATE IS NULL and [Case Owner] = '"
+ getTheUserDetails.getUserNameDetails(systemUserName) + "'";
System.out.println("Query is " + queryString);
rs = stmt.executeQuery(queryString);
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("bno of cols are " + rsmd.getColumnCount());
while (rs.next()) {
if (rs.next()) {
UserBean userBean = new UserBean();
userBean.setCaseNumber(rs.getString(1));
userBean.setCaseOwner(rs.getString(2));
userBean.setStatus(rs.getString(4));
userBean.setIssue(rs.getString(5));
userBean.setReason(rs.getString(6));
userBean.setDateOpened(rs.getString(7));
userBean.setAge(rs.getInt(8));
userBeans.add(userBean);
} else {
UserBean userBean = new UserBean();
userBean.setCaseNumber("None");
userBean.setCaseOwner("None");
userBean.setStatus("None");
userBean.setIssue("None");
userBean.setReason("None");
userBean.setDateOpened("None");
userBean.setAge(Integer.parseInt("None"));
userBeans.add(userBean);
}
}

rs.close();
conn.commit();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return userBeans;
}
}

根据我的理解,我已经尝试编写了以下算法,

if(rs.next)
then create the bean and add the values from database,
else
create the bean and add the values as None

请让我知道我哪里出了问题以及如何解决这个问题。

谢谢

最佳答案

if(rs.next)
then create the bean and add the values from database,
else
set the bean as null

在 jsp 中检查 bean 是否为 null,然后在文本框下检查无可用数据。理想情况下,您应该在 servlet 或 Controller 中执行此操作,因为 jsp 应该尽可能轻

关于java - 用空值填充文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35943739/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com