gpt4 book ai didi

java - 未找到列 Access 数据库

转载 作者:行者123 更新时间:2023-12-02 02:34:23 25 4
gpt4 key购买 nike

我正在创建一个地址簿应用程序,并且正在开发搜索功能。每当我搜索时,我都会收到“未找到列”异常。这是我的代码:

else if(actionCommand.contentEquals("search"))
{
String searchInput = searchBar.getText();
//String[] searchSplit = searchInput.split("\\s");
//String searchFirst = searchSplit[0];
//String searchLast = searchSplit[1];
personID = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:address_book");
Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery("SELECT (personID) FROM names WHERE (lastName) LIKE ('"+searchInput+"')");
if(resultSet.next())
personID = resultSet.getString("personID");

ResultSet firstQuery = statement.executeQuery("SELECT (firstName) FROM names WHERE (personID) LIKE ('"+personID+"')");
if(firstQuery.next())
firstNameOutput = firstQuery.getString("firstName");

ResultSet lastQuery = statement.executeQuery("SELECT (lastName) FROM names WHERE (personID) LIKE ('"+personID+"')");
if(lastQuery.next())
lastNameOutput = lastQuery.getString("lastName");

ResultSet address1Query = statement.executeQuery("SELECT (address1) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(address1Query.next())
address1Output = address1Query.getString("address1");

ResultSet address2Query = statement.executeQuery("SELECT (address2) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(address2Query.next())
address2Output = address2Query.getString("address1");

ResultSet cityQuery = statement.executeQuery("SELECT (city) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(cityQuery.next())
cityOutput = cityQuery.getString("city");

ResultSet stateQuery = statement.executeQuery("SELECT (state) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(stateQuery.next())
stateOutput = stateQuery.getString("state");

ResultSet zipcodeQuery = statement.executeQuery("SELECT (zipcode) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(zipcodeQuery.next())
zipcodeOutput = zipcodeQuery.getString("zipcode");

ResultSet phoneQuery = statement.executeQuery("SELECT (phoneNumber) FROM phoneNumbers WHERE (personID) LIKE ('"+personID+"')");
if(phoneQuery.next())
phoneOutput = phoneQuery.getString("phoneNumber");

ResultSet emailQuery = statement.executeQuery("SELECT (emailAddress) FROM emailAddresses WHERE (personID) LIKE ('"+personID+"')");
if(emailQuery.next())
emailOutput = emailQuery.getString("emailAddress");

newFunctionWindow();
personIDBar.setText(personID);
firstNameBar.setText(firstNameOutput);
lastNameBar.setText(lastNameOutput);
address1Bar.setText(address1Output);
address2Bar.setText(address2Output);
cityBar.setText(cityOutput);
stateBar.setText(stateOutput);
zipcodeBar.setText(zipcodeOutput);
phoneBar.setText(phoneOutput);
emailBar.setText(emailOutput);
statement.close();
connection.close();
}

catch (SQLException sqlException)
{
JOptionPane.showMessageDialog(null, sqlException.getMessage(), "Database Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}

catch (ClassNotFoundException classNotFound)
{
JOptionPane.showMessageDialog(null, classNotFound.getMessage(), "Driver Not Found", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}

我仔细检查了所有列名称,没有拼写错误。我相信我所有的 SQL 语句也是正确的,所以我不太确定问题是什么!感谢您的帮助。

最佳答案

        ResultSet address1Query = statement.executeQuery("SELECT (address1) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(address1Query.next())
address1Output = address1Query.getString("address1");

ResultSet address2Query = statement.executeQuery("SELECT (address2) FROM addresses WHERE (personID) LIKE ('"+personID+"')");
if(address2Query.next())
address2Output = address2Query.getString("address1");

哎呀 - 地址 1 来自地址 2 字段?那是行不通的。 (引用最后一行)

关于java - 未找到列 Access 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46613428/

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