在textfield java中获取数据库值 [英] Get a database value in a textfield java
本文介绍了在textfield java中获取数据库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们,
我试图在txtfield中显示存储在数据库中的name值。但是当我执行程序并单击按钮时没有任何反应。我可以告诉你为什么吗?
H guys,
I am trying to show the "name" value which is stored in the database, in the txtfield. But when I execute the program and click on the button nothing happens. Can me someone tell why??
btnStudent.addActionListener((ActionListener) new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String newquery = "SELECT * FROM test";
ps= (PreparedStatement) con.prepareStatement(newquery);
rs = ps.executeQuery();
if(rs.next()){
//JOptionPane.showMessageDialog(null, rs.getString("name"));
txtfldName= rs.getString("name");
}
Thx提前全部。
我尝试过:
编程代码并尝试了很多来获取txtfldName中的字符串但没有任何效果。
Thx all in advance.
What I have tried:
program the code and tried a lot to get the string in the txtfldName but nothing worked.
推荐答案
关注此
Follow this
String newquery = "SELECT * FROM test";
DatabaseConnection db = new DatabaseConnection();
Connection conn = db.getConnection();
Statement st = conn.createStatement(); // create the java statement
ResultSet rs = st.executeQuery(query); // execute the query, and get resultset
while (rs.next()){ // iterate through the java resultset
//JOptionPane.showMessageDialog(null, rs.getString("name"));
txtfldName= rs.getString("name");
}
st.close();
rs.close();
conn.close();
这篇关于在textfield java中获取数据库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文