使用逻辑运算符 and or not
1.查询出年龄在15—20之间的所有人信息(包含)
select * from user where age>=15 and age<=20;
select * from user where age between 15 and 20;
2.查询出年龄大于15且性别为女的用户信息
select * from user where age>15 and sex='女';
3.查询出年龄大于15岁或者性别为女的用户信息
select * from user where age>15 or sex='女';
4.查询出年龄为15或16或17的用户信息
select * from user where age=15 or age=16 or age=17;
select * from user where age in(15,16,17);
5.查询出年龄不是15岁的用户信息
select * from user where age!=15;// 不等号可以用 != 和 <>
select * from user where not age=15;
使用模糊查询like
%: 0—n个任意字符
_: 1个任意字符
1.查询出姓王的用户信息
select * from user where name like '王%';
2.查询出名字中包含王的用户信息
统计数据、记录的条数
select count(*) from 表名 [where 条件];
JDBC连接
Eg://加载MySQL驱动
Class.forName("com.mysql.jdbc.Driver");
Eg://加载Oracle驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
3.发送SQL语句
通过Connection对象获得Statement对象,再使用Statement对象发送SQL语句。
Eg://取得Connection对象
Statement st = conn.createStatement();
Eg://发送SQL语句
ResultSet rs = st.executeQuery("select * from student");//执行查询
int x = st.executeUpdate("delete from student where sex='女'");//执行删除
1.查询出年龄在15—20之间的所有人信息(包含)
select * from user where age>=15 and age<=20;
select * from user where age between 15 and 20;
2.查询出年龄大于15且性别为女的用户信息
select * from user where age>15 and sex='女';
3.查询出年龄大于15岁或者性别为女的用户信息
select * from user where age>15 or sex='女';
4.查询出年龄为15或16或17的用户信息
select * from user where age=15 or age=16 or age=17;
select * from user where age in(15,16,17);
5.查询出年龄不是15岁的用户信息
select * from user where age!=15;// 不等号可以用 != 和 <>
select * from user where not age=15;
使用模糊查询like
%: 0—n个任意字符
_: 1个任意字符
1.查询出姓王的用户信息
select * from user where name like '王%';
2.查询出名字中包含王的用户信息
统计数据、记录的条数
select count(*) from 表名 [where 条件];
JDBC连接
Eg://加载MySQL驱动
Class.forName("com.mysql.jdbc.Driver");
Eg://加载Oracle驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
3.发送SQL语句
通过Connection对象获得Statement对象,再使用Statement对象发送SQL语句。
Eg://取得Connection对象
Statement st = conn.createStatement();
Eg://发送SQL语句
ResultSet rs = st.executeQuery("select * from student");//执行查询
int x = st.executeUpdate("delete from student where sex='女'");//执行删除