一、字段数据类型 二、MySQL中的SQL语句 1. 数据库操作 -- 查看数据库show databases;-- 创建数据库create database db_num;-- 使用数据库use db_num;-- 删除数据库drop database db_num; 2. 表操作 -- 查看数据库中的表show tables;-- 创建表create table t_num( nno varchar(36) primary key, nnum int(7) not null, ntype char(2));-- 查看表结构desc t_num;-- 显示建表SQL语句show create table t_num;-- 删除表drop table t_num; 3. 增删改查 -- 插入insert into t_num values ('abcdefghijklmn',2,'ZS');-- 查询select * from t_num;-- 修改update t_num set nnum=3 where nnum=2;-- 删除delete from t_num where nnum=2; 注意:在MySQL中,SQL语句操作和Oracle大致相同,在插入操作中,varchar类型数据要用双引号,char则使用单引号。 三、JDBC操作MySQL 1. 更改jdbc.properties配置文件 说明:通过更改dbtype来切换连接Oracle还是MySQL 2. 更新DBUtil工具类 static { Properties prop = new Properties(); try { prop.load(DBUtil.class.getResourceAsStream('/jdbc.properties')); String dbtype = prop.getProperty('dbtype'); driver = prop.getProperty(dbtype + 'driver'); url = prop.getProperty(dbtype + 'url'); user = prop.getProperty(dbtype + 'user'); password = prop.getProperty(dbtype + 'password'); Class.forName(driver); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); }} 只需更新静态代码块中读取配置文件的操作即可! |
|
来自: 庆亮trj21bcn0z > 《数据库》