课程总结

JDBC驱动程序分为四类:

1)JDBC-ODBC桥驱动;
2)JDBA本地驱动;
3)JDBC网络驱动;
4)本地协议纯JDBC驱动;

JDBC的连接地址实际上是由以下的3个部分组成。

(1)jabc 协议:JDBC URL 中的协议总是 jdbc。
(2)子协议:驱动程序名或数据库连接机制(这种机制可由一个或多个驱动程序支持)的名称,如
MySQL。
(3)子名称: 种标识数据库的方法。必须遵循“//主机名:端口/子协议”的标准URL 命名约定,
如//localhost:3306/mldn

加载驱动程序:

Class.forName(driverClass)
//加载MySql驱动
Class.forName("com.mysql.jdbc.Driver")
//加载Oracle驱动
Class.forName("oracle.jdbc.driver.OracleDriver")

数据库语言

1、增加数据

insert into 表名称[(字段1,字段2,....字段n)]values(值1,值2.....值n);

2、删除数据

delete 表名称[删除条件];

3、更新数据

update 表名称 set 字段1=值1......字段n=值1[where 更新条件];

4查询数据

select{*|column alias}
from 表名称 别名
[where condition(s)];        //设置查询条件

简易记事本

实验代码

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.EventObject;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;

import junit.framework.Test;

public  class jishiben implements ActionListener{
	JFrame frame;
	JMenu q,w,e,r,t;
	JTextArea wb;
	JMenuBar bar;
	JMenuItem one,two,theer,four,five,one1,two1,theer1;
	JFileChooser open;
	File file;



public   jishiben() {
	
    	 frame=new JFrame("记事本");
    	
    	 bar=new JMenuBar();
    	
    	 q=new JMenu("文件(F)");
    	 w=new JMenu("编辑(E)");
    	 e=new JMenu("格式(O)");
    	 r=new JMenu("查看(V)");
    	 t=new JMenu("帮助(H)");
    	
    	 wb=new JTextArea();
    	
    	 one=new JMenuItem("新建(N)");
    	 two=new JMenuItem("打开(O)");
    	 theer=new JMenuItem("保存(S)");
    	 four=new JMenuItem("另存为(A)");
    	 five=new JMenuItem("退出(X)");
    	
    	 one1=new JMenuItem("撤销(U)");
    	 two1=new JMenuItem("复制(C)");
    	 theer1=new JMenuItem("粘贴(P)");
    	
    	
    	
    	
    	
    	q.setMnemonic('F');
    	w.setMnemonic('E');
    	e.setMnemonic('O');
    	r.setMnemonic('V');
    	t.setMnemonic('H');
    	
    	one1.setMnemonic('U');
    	two1.setMnemonic('C');
    	theer1.setMnemonic('P');
    	
    	
    	one.setMnemonic('N');
    	two.setMnemonic('O');
    	theer.setMnemonic('s');
    	four.setMnemonic('A');
    	five.setMnemonic('X');
    	
    	//q.setAccelerator(KeyStroke.getKeyStroke('F',java.awt.Event.ALT_MASK));
    	
    	one.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));
    	two.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK));
    	theer.setAccelerator(KeyStroke.getKeyStroke('S',java.awt.Event.CTRL_MASK));
    	four.setAccelerator(KeyStroke.getKeyStroke('A',java.awt.Event.CTRL_MASK));
    	five.setAccelerator(KeyStroke.getKeyStroke('X',java.awt.Event.CTRL_MASK));
    	
    	one1.setAccelerator(KeyStroke.getKeyStroke('U',java.awt.Event.CTRL_MASK));
    	two1.setAccelerator(KeyStroke.getKeyStroke('C',java.awt.Event.CTRL_MASK));
    	theer1.setAccelerator(KeyStroke.getKeyStroke('P',java.awt.Event.CTRL_MASK));
    	
    	
    	  one.addActionListener(this);
          two.addActionListener(this);
          theer.addActionListener(this);
          four.addActionListener(this);
          five.addActionListener(this);
    	
    	q.add(one);
    	q.add(two);
    	q.add(theer);
    	q.add(four);
    	q.addSeparator();
    	q.add(five);
    	
    	w.add(one1);
    	w.add(two1);
    	w.add(theer1);
    	
    	bar.add(q);
    	bar.add(w);
    	bar.add(e);
    	bar.add(r);
    	bar.add(t);
    	
    	frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent arg0) {
				System.exit(1);
			}
		});
    	frame.add(wb);
    	frame.setJMenuBar(bar);
    	frame.setVisible(true);
    	frame.pack();
    	frame.setLocation(300,300);
    	
    }





	@Override
	public void actionPerformed(ActionEvent event) {
		 
		Object obj=event.getSource();
	        if(obj instanceof JMenuItem) {
	            JMenuItem item=(JMenuItem) obj;
	        
	            if(item==one) {
	                new jishiben();
	            }
	       
	            else if(item == two){
	                open=new JFileChooser();
	                open.showOpenDialog(null);
	                file = open.getSelectedFile();
	                try {
	                    FileInputStream fis=new FileInputStream(file);
	                    byte[] b=new byte[fis.available()];
	                    fis.read(b);
	                    wb.append(new String(b));
	                    fis.close();
	                }catch(FileNotFoundException e) {
	                    e.printStackTrace();
	                } catch (IOException e) {
	                    // TODO Auto-generated catch block
	                    e.printStackTrace();
	                }
	            }
	          else if(item == theer) {
             
         }

	            else if(item ==four) {
	                open=new JFileChooser();
	                open.showSaveDialog(null);
	                file = open.getSelectedFile();
	                try {
	                    if(!file.exists()) {
	                        file.createNewFile();
	                    }
	                    FileOutputStream fos=new FileOutputStream(file);
	                    byte[] b = wb.getText().getBytes();
	                    fos.write(b);
	                    fos.close();
	                }catch(IOException c) {
	                    c.printStackTrace();
	                }
	            }else if(item== five) {
	                System.exit(1);
	            }
	        }   
	}
}

测试代码:


public class jishibenTest {
	 public static void main(String[] args) {
	        new jishiben();
	    }
}

新建:

打开

保存