Java中jdbc数据库连接

1.ipconfig :查看本机ip地址

2.ping ip地址:检查网络是否连通

insert into student (id,name,age,sex) values (1,'张三',18,'男');
insert into student values (2,'柳岩',20,'2000-01-09','','安徽');
insert into student (id,name,age,birthday,sex,address) values (3,'戚薇',20,'2000-01-09','','安徽');
insert into student values (4,'赵丽颖',20,'1990-01-09','','安徽'),(5,'李佳琦',20,'1990-01-09','','安徽');
insert into student (id,name,age,birthday,sex,address) values (6,'历史',12,'2020-01-09','男',null);
update student set sex = '男';
update student set sex = '女' where id =2;
select * from student st where st.id = 4;
update student set address = '北京' , birthday = '2001-09-01' where id =1;
delete from student where id = 1;
delete from student st where id in (5,6);
select distinct age from student;
select * from student where age <> 20;
select * from student where age !=20;
update  student stu set age = 19 ;
select * from student where id in (1,2,3);
select * from student where id not in (1,2,3);
select * from student where math between 70 and 90;
select * from student where name like '赵__';
select * from student order by age desc;
select * from student order by age desc ,math desc ;
select sum(math)+sum(english) from student;
select sum(math+english) from student;

create table car(
  id int,
  color char(2),
  price float
);

select color, sum(price) from car group by color;
select color ,sum(price) from car group by color having sum(price)>30;
select color ,sum(price) from car where price >15 group by color having  sum(price) > 30;


select * from car limit 0,2;









```java
public class JDBCTest01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
       // Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=utf8";
        String user = "root";
        String password = "123456";
        Connection connection = DriverManager.getConnection(url, user, password);
        String sql = "select * from userinfo";
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int age = resultSet.getInt("age");
            int sex = resultSet.getInt("sex");
            System.out.println("id:"+id+" name:"+name+" age:"+age+" sex:"+sex);
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}

select sum(ifnull(math,0)+ifnull(english,0)) as score from student


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值