使用Java在jtable和数据库中添加行(Adding row in jtable and database using Java)
我的代码有问题,它没有错误日志,所以我看不到问题。 。 。
Current Problem: Mainclass() is where the main frame is. . . Clicking ADD will open AddBroker() and clicking ADD in AddBroker() will update databse and jtable in MainClass(). Database can now be updated but the jtable in MainClass() won't change until you open it again
这是我的主要课程(其他代码被编辑以关注问题)
public class MainClass extends JFrame { JButton button_17 = new JButton("ADD"); button_17.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //to call class AddBroker() AddBroker ab = new AddBroker(); ab.setVisible(true); } });}
然后这是AddBroker()的类。 。 。
public class AddBroker extends JFrame { JButton btnAdd = new JButton("ADD"); final Object[] addBrokerrow = new Object[3]; btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { ButtonCon bcd = new ButtonCon(); DriverTableCon dtcd = new DriverTableCon(); //this is just jtable MainClass mcd = new MainClass(); String a = brokerBroker.getText(); String b = addBroker.getText(); String c = tinBroker.getText(); addBrokerrow[0] = a; addBrokerrow[1] = b; addBrokerrow[2] = c; dtcd.modelBroker.addRow(addBrokerrow); bcd.addBrokerCon(a,b,c); } });}
而ButtonCon()是数据添加的地方
public class ButtonCon { Connection con; Statement st; ResultSet rs; StringBuffer results; String url = "jdbc:ucanaccess://C://DATABASE//NTD.accdb"; public void addBrokerCon(String broker, String add, String tin) { try { con = DriverManager.getConnection(url); String sql = "INSERT INTO brokerT (Broker, Address, Tin_No) VALUES (?,?,?)"; ps = con.prepareStatement(sql); ps.setString(1, broker); ps.setString(2, add); ps.setString(3, tin); ps.executeUpdate(); ps.close(); con.close(); } catch (Exception e) { System.out.print(e.toString()); } } }
没有错误,所以我不知道这里有什么问题。 任何输入将不胜感激:)
所以这已经过去了一个星期,我试图解决这个问题,我做的是添加一个“刷新”按钮,再次加载表格。
I have a problem with my code and it has no error log so I can't see the problem . . .
Current Problem: Mainclass() is where the main frame is. . . Clicking ADD will open AddBroker() and clicking ADD in AddBroker() will update databse and jtable in MainClass(). Database can now be updated but the jtable in MainClass() won't change until you open it again
This is my main class (other codes were redacted to focus on problem)
public class MainClass extends JFrame { JButton button_17 = new JButton("ADD"); button_17.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { //to call class AddBroker() AddBroker ab = new AddBroker(); ab.setVisible(true); } });}
Then this is the class for AddBroker(). . .
public class AddBroker extends JFrame { JButton btnAdd = new JButton("ADD"); final Object[] addBrokerrow = new Object[3]; btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { ButtonCon bcd = new ButtonCon(); DriverTableCon dtcd = new DriverTableCon(); //this is just jtable MainClass mcd = new MainClass(); String a = brokerBroker.getText(); String b = addBroker.getText(); String c = tinBroker.getText(); addBrokerrow[0] = a; addBrokerrow[1] = b; addBrokerrow[2] = c; dtcd.modelBroker.addRow(addBrokerrow); bcd.addBrokerCon(a,b,c); } });}
And ButtonCon() is where the adding of data is
public class ButtonCon { Connection con; Statement st; ResultSet rs; StringBuffer results; String url = "jdbc:ucanaccess://C://DATABASE//NTD.accdb"; public void addBrokerCon(String broker, String add, String tin) { try { con = DriverManager.getConnection(url); String sql = "INSERT INTO brokerT (Broker, Address, Tin_No) VALUES (?,?,?)"; ps = con.prepareStatement(sql); ps.setString(1, broker); ps.setString(2, add); ps.setString(3, tin); ps.executeUpdate(); ps.close(); con.close(); } catch (Exception e) { System.out.print(e.toString()); } } }
There is no error so I have no idea what is wrong here. Any input would be appreciated :)
So it's been a week and what I did try to solve the problem and what I did is add a "Refresh" button that loads the table again.
原文:https://stackoverflow.com/questions/42452621
满意答案
假设=是在类别行的末尾....
将文件保存到(例如)foo.txt在Solaris上使用nawk,而不是awk。
awk '/=$/ && !arr[$0]++ {print; next} {print $0} ' foo.txt > newfile.txt
抱歉。 我没有清楚的想法如何在没有大量打字工作或使用复杂的ed文件的情况下在vi / vim中执行此操作。 其他人可能有一个想法。 如果你完全陷入困境,请尝试以上方法。
Assuming = is there at the end of category lines....
Save the file to (for example) foo.txt Use nawk on Solaris, not awk.
awk '/=$/ && !arr[$0]++ {print; next} {print $0} ' foo.txt > newfile.txt
Sorry. I do not have a clear idea how to do this in vi/vim without massive typing efforts or using a complex ed file. Someone else may have an idea. If you are totally stuck, try the above.
相关问答
更多Unix:删除不排序的重复行(Remove duplicate lines without sorting [duplicate])
用于格式化PHP代码的Unix或VIM命令(Unix or VIM command to format PHP code)
Vim:更改特定目录的文件格式[重复](Vim: Change the file format for a particular directory [duplicate])
使用vim删除unix中的重复字段(remove duplicate fields in unix with vim)
Vim(7.3.3 Windows 64位):如果没有(^ f = unix),将^ M加到行尾(Vim (7.3.3 Windows 64bit): Add ^M to end of line if there is none (ff=unix))
如何为vim中的所有文件设置fileformat = unix?(How to set fileformat=unix for all files opend in vim?)
如何删除vim Powerline中的段?(How to remove a segment in vim Powerline?)
在vim中粘贴文本[重复](Pasting texts in vim [duplicate])
在vim中缩进[重复](Indenting in vim [duplicate])
相关文章
更多HDFS导出数据到HBase的ROW VALUE设置tricks
Hive 终端产生的问题 (Failed to start database 'metastore_db', see the next exception for details.)
HTML5 Web SQL Database 数据库
《Oracle Database 11g SQL开发指南》(Oracle Database 11g SQL )扫描版[PDF]
myEclipse8.5 New DataBase Connection Driver时出错
《Oracle Database 11g DBA手册》(Oracle Database 11g DBA Handbook )扫描版[PDF]
《数据库系统基础:初级篇(第5版)》(Fundamentals of Database Systems (5th Edition))扫描版[PDF]
《数据库系统基础:高级篇(第5版)》(Fundamentals of Database Systems (5th Edition) )扫描版[PDF]
《Oracle Database 10g DBA手册-管理健壮的、可扩展的、高可用的Oracle数据》(Oracle Database 10g DBA Handbook)扫描版[PDF]
POI读取数据库数据到excel
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!