SnameText.setText(resultSet.getString("Sname"));
时间: 2024-04-05 10:29:44 浏览: 12
这行代码是将查询结果集(ResultSet)中的名为 "Sname" 的列的值,赋值给名为 "SnameText" 的文本框(TextField)的文本属性(text)。具体来说,ResultSet.getString() 方法返回指定列的值(即 Sname 列的值),然后将该值设置为文本框的文本属性,以在用户界面中展示该值。
相关问题
if (e.getSource() == seek && type == 3) { PreparedStatement state; ResultSet resultSet; try { state = connection.prepareStatement("select Sname,Ssex,Sdept,Dno,Bbu from student where Sno =" + "'" + Sno.getText() + "'"); resultSet = state.executeQuery(); while (resultSet.next()) { //suse.setText("电话"); SnameText.setText(resultSet.getString("Sname")); SsexText.setText(resultSet.getString("Ssex")); SdeptText.setText(resultSet.getString("Sdept")); DnoText.setText(resultSet.getString("Dno")); BbuText.setText(resultSet.getString("Bbu")); } } catch (SQLException e1) { e1.printStackTrace(); }
根据你提供的代码,它是一个 Java 语言的片段,主要是在处理用户界面跟数据库交互的逻辑,具体来说,它是在根据用户输入的学号查询数据库中对应的学生信息,然后将查询结果展示在用户界面的文本框中。在代码中,使用了 JDBC(Java 数据库连接)技术来连接数据库,并通过 SQL 语句执行查询操作,最终将查询结果封装在一个 ResultSet 对象中,再通过调用 ResultSet 对象的方法来获取具体的查询结果。如果在查询过程中发生了异常,代码会打印出异常的堆栈信息。
db.execSQL("update user set Name=? ,Nickname=?,Age=?",new Object[]{name,nickname,age}); Cursor cursor= db.rawQuery("select*from user where Account=?",new String[]{account}); editTextname.setText(cursor.getString(2)); editTextnickname.setText(cursor.getString(3)); editTextage.setText(cursor.getString(4)); cursor.close();显示更新的数据哪错了
这段代码有几个问题:
1. `update` 语句中的参数应该是按照字段的顺序传递的,而不是按照字段名称。因此,应该将 `Name`、`Nickname`、`Age` 改为对应的字段顺序(假设是第 2、3、4 个字段)。
2. 在执行 `rawQuery` 方法时,需要先调用 `moveToFirst` 方法将结果集指针移动到第一条记录上,然后才能获取数据。因此,在调用 `cursor.getString` 方法之前,应该先调用 `cursor.moveToFirst` 方法。
修改后的代码应该是这样的:
```
db.execSQL("update user set ?, ?, ? where Account=?", new Object[]{name, nickname, age, account});
Cursor cursor = db.rawQuery("select * from user where Account=?", new String[]{account});
if (cursor.moveToFirst()) {
editTextname.setText(cursor.getString(2));
editTextnickname.setText(cursor.getString(3));
editTextage.setText(cursor.getString(4));
}
cursor.close();
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)