In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.Vector;import javax.swing.*;import javax.swing.table.DefaultTableModel / / layout manager of the form: boundary, grid, / / the table model collection class connects to the database / / what actually stores data is the table model public class W extends JFrame implements ActionListener {/ / Parameter properties JButton an1; JLabel bq; JTextField wbk; JPanel mb;// panel composition: container, put components, the default layout manager is: streaming layout JTable bg; JScrollPane gd; Vector jilu,ziduan; Connection con;// connection database PreparedStatement ps / execute SQl statement ResultSet rs;// DefaultTableModel bgmx; public W () {/ / Northern an1=new JButton ("query"); an1.addActionListener (this); bq=new JLabel ("Please enter user name:"); wbk=new JTextField (10); mb=new JPanel (); mb.add (bq); mb.add (wbk); mb.add (an1); this.add (mb,BorderLayout.NORTH); / / Central ziduan=new Vector () Ziduan.add ("student number"); ziduan.add ("name"); ziduan.add ("gender"); ziduan.add ("age"); ziduan.add ("place of origin"); ziduan.add ("department name"); jilu=new Vector (); / / connect to the database try {Class.forName ("com.mysql.jdbc.Driver"); / / load driver String url= "jdbc:mysql://localhost:3306/student"; String user= "root" String password= "000000"; con=DriverManager.getConnection (url, user, password); if (contextual null) {System.out.println ("Database connection successful");} ps=con.prepareStatement ("delete from c where xuehao='xs002'"); ps.executeUpdate (); ps=con.prepareStatement ("select * from c"); rs=ps.executeQuery (); while (rs.next ()) {Vector hang=new Vector (); hang.add (rs.getString (1)) Hang.add (rs.getString (2)); hang.add (rs.getString (3)); hang.add (rs.getInt (4)); hang.add (rs.getString (5)); hang.add (rs.getString (6)); jilu.add (hang);} catch (Exception e) {} finally {try {if (rswatches null) {rs.close ();} if (psometric null) {ps.close () } if (contextual null) {con.close ();} catch (Exception e) {}} bgmx=new DefaultTableModel (jilu,ziduan); bg=new JTable (bgmx); gd=new JScrollPane (bg); this.add (gd); this.setTitle ("this is a form"); this.setSize (350350); this.setVisible (true); this.setDefaultCloseOperation (EXIT_ON_CLOSE);} public static void main (String [] args) {new W () } @ Override public void actionPerformed (ActionEvent e) {/ / TODO Auto-generated method stub if (e.getSource () = = an1) {JOptionPane.showConfirmDialog (this, "are you sure you want to close the horse?") ;}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.