A, JDBC
JDBC, provides a platform-independent standard for executing SQL statements of Java API, it can easily achieve a variety of relational database unified operation, which consists of a set written in java language classes and interfaces.
JDBC drivers are divided into: JDBC-ODBC bridge driver, a local JDBC driver, JDBC network drives, local protocol pure JDBC driver.
JDBC primary action classes and interfaces
Two, MySQL database
commonly used commands
connect to the MySQL database
mysql -u 用户名 -p 密码
Create a database
创建数据库:CREATE DATABASE 数据库名称;
删除数据库:DROP DATABASE 数据库名称;
Use Database
USE 数据库名称
Create a database table
CREATE TABLE 表名称(
字段名称1 字段类型 [DEFAULT 默认值][约束]
字段名称2 字段类型 [DEFAULT 默认值][约束]
...,
);
To delete a database table
DROP TABLE 表名称;
View table structure
DESC表结构 ;
Database Information
查看全部数据库SHOW TABLES;
查看一个数据库的全部表SHOW DATABASES;
Third, notepad
experiment code
package text;
import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.*;
import java.io.*;
public class JNodepad extends JFrame implements ActionListener {
JMenuBar menubar = new JMenuBar();
JMenu file = new JMenu("文件(F)");
JMenu edit = new JMenu("编辑(E)");
JMenu help = new JMenu("帮助(H)");
JMenuItem create = new JMenuItem("新建");
JMenuItem open = new JMenuItem("打开...");
JMenuItem save = new JMenuItem("保存");
JMenuItem exit = new JMenuItem("退出");
JFrame frame;
JMenuBar bar;
JMenu fileMenu,editMenu;
JMenuItem newItem,openItem,saveItem,closeItem,fnewItem,anothersaveItem;
ImageIcon newIcon,saveIcon,closeIcon,openIcon;
JScrollPane scroll;
JTextArea area;
JFileChooser chooser;
File file;
public Test() {
frame =new JFrame("记事本");
bar =new JMenuBar();
fileMenu =new JMenu("文件");
editMenu =new JMenu("编辑");
newIcon = new ImageIcon("d:" + File.separator + "test" + File.separator +"新建.png");
openIcon = new ImageIcon("d:" + File.separator + "test" + File.separator +"打开.png");
saveIcon = new ImageIcon("d:" + File.separator + "test" + File.separator +"保存.png");
closeIcon = new ImageIcon("d:" + File.separator + "test" + File.separator +"关闭.png");
area =new JTextArea();
scroll =new JScrollPane(area);
newItem =new JMenuItem("新窗口(N)",newIcon);
openItem =new JMenuItem("打开(O)",openIcon);
saveItem =new JMenuItem("保存(S)",saveIcon);
closeItem =new JMenuItem("关闭(X)",closeIcon);
anothersaveItem=new JMenuItem("另存为(A)",saveIcon);
fnewItem =new JMenuItem("新建(N)");
//监听器
fnewItem.addActionListener(this);
newItem.addActionListener(this);
openItem.addActionListener(this);
saveItem.addActionListener(this);
closeItem.addActionListener(this);
anothersaveItem.addActionListener(this);
fileMenu.add(newItem);
fileMenu.add(openItem);
fileMenu.add(saveItem);
fileMenu.add(closeItem);
fileMenu.add(fnewItem);
fileMenu.add(anothersaveItem);
fileMenu.addSeparator();
menubar.add(file);
menubar.add(edit);
menubar.add(help);
textarea.add(popup);
textarea.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
popup.show();
}
}
};
this.add(menubar, BorderLayout.NORTH);
this.add(scroll, BorderLayout.CENTER);
this.setTitle("记事本");
this.setSize(500, 400);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == open) {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("文本文档(*.txt)", "txt");
chooser.setFileFilter(filter);
chooser.setDialogTitle("文件打开");
chooser.showOpenDialog(null);
chooser.setVisible(true);
}
if (e.getSource() == save && (pathSelect == null)) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("保存");
chooser.showSaveDialog(null);
chooser.setVisible(true);
PrintStream ps;
try {
pathSelect = chooser.getSelectedFile().getPath();
ps = new PrintStream(pathSelect);
System.setOut(ps);
System.out.println(this.textarea.getText());
} catch (Exception e1) {
}
} else if (e.getSource() == save && !(pathSelect == null)) {
PrintStream ps;
try {
ps = new PrintStream(pathSelect);
System.setOut(ps);
System.out.println(this.textarea.getText());
} catch (FileNotFoundException e1) {
}
}
if (e.getSource() == create) {
textarea.setText("");
pathSelect = null;
}
if (e.getSource() == exit) {
System.exit(0);
}
}
public static void main(String[] args) {
new JNodepad();
}
}