整数类型

小数类型
(M, D)来表示,其中M称为精度,表示总共的位数;D称为标度,表示小数的位数。

日期和时间类型

==字符串类型==

create database 数据库名称create database if not exists 数据库名称create database 数据库名称 character set 字符集名show databasesshow create database 数据库名称alter database 数据库名称 character set 字符集名称dorp database 数据库名称drop database if exists 数据库名称select database()use 数据层名称create table 表名 like 被复制的表名show tablesdesc 表名alter table 表名 rename to 新的表名alter table 表名 character set 字符集名称alter table 表名 add 列名 数据类型alter table 表名 change 列名 新列别 新数据类型alter table 表名 drop 列名drop table if exists 表名insert into 表名(列名1,列名2..) values(值1,值2...)delete from 表名 [where 条件]update 表名 set 列名1=值1,列名2=值2,... [where 条件]distinct
like '%字符%'
order by 排序字段1 排序方式1 create user '用户名'@'主机名' identified by '密码'drop user '用户名'@'主机名'set password for '用户名'@'主机名' =password('新密码')use mysqlselect * from usershow grants for '用户名'@'主机名'grant 权限列表 on 数据库名.表名 to '用户名'@'主机名'grant all on *.* to '用户名'@'主机名'revoke 权限列表 on 数据库.表名 from '用户名'@'主机名'net stop mysqlmysqld --skip-grant-tableuse mysqlupdate user set password = password('你的新密码') where user = 'root';使用 SHOW CREATE TABLE <数据库表名>语句来查看表中的约束
alter table 表名 modify 字段 类型 not nullalter table 表名 modify 字段类型alter table 表名 drop index 字段alter table 表名 modify 字段 类型 uniquealter table 表名 drop primary keyalter table 表名 add primary key(字段)alter table 表名 modify 字段 类型alter table 表名 modify 字段 类型 auto_incrementalter table 表名 drop foreign key 外键名称alter table 表名 add constraint 外键名称 foreign key (外键字段名称) references 主表名称(主表列名称)存在问题:
url=jdbc:mysql:///数据库名
user=root
password=root
driver=com.mysql.jdbc.Driverpublic class JdbcUtils {
private static String url;
private static String user;
private static String password;
private static String driver;
//使用静态代码块,随着类的加载而执行,而且只执行一次
static {
try {
//创建Properties集合类
Properties pro = new Properties();
//获取src路径下的文件的方式--->ClassLoader 类加载器
ClassLoader loader = JdbcUtils.class.getClassLoader();
URL res = loader.getResource("jdbc.properties");
String path = res.getPath();
pro.load(new FileReader(path));
//pro.load(new FileReader("src/jdbc.properties"));
url = pro.getProperty("url");
user = pro.getProperty("user");
password = pro.getProperty("password");
driver = pro.getProperty("driver");
Class.forName(driver);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//获取连接对象
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, user, password);
}
//释放资源
public static void close(Statement stmt, Connection conn) {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void close(ResultSet rs, Statement stmt, Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}Spring框架对JDBC的简单封装。提供了一个JDBCTemplate对象简化JDBC的开发
步骤: