mysqldemo.java
来自「一个用java开发的具有搜索功能的图书管理系统」· Java 代码 · 共 102 行
JAVA
102 行
package library;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
public class MySQLDemo extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Test");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
MySQL mysql;
try {
mysql = new MySQL("jdbc:mysql://localhost/mysql","root","");
ResultSet bulletinRS=mysql.getResultSet("select title,promulgateDate,bulletinID from bulletin order by bulletinID desc limit 0,10;");
while(bulletinRS.next())
{
System.out.println(bulletinRS.getString("title"));
}
mysql.closeMySQL();
} catch (ClassNotFoundException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
} catch (SQLException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
}
});
}
return jButton;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MySQLDemo thisClass = new MySQLDemo();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public MySQLDemo() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJButton(), BorderLayout.SOUTH);
}
return jContentPane;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?