课下作业补做

一、加载JDBC-数据库驱动。

    try{ Class. forName("com.mysql.jdbc.Driver");
        }
    catch(Exception e){}

二、连接数据库

    Connection con;
    String uri =
    "jdbc:mysql://192.168.100.1:3309/name?user=root&password=&useSSL=true";
    try{
        con = DriverManager.getConnection(uri);
    }
    catch(SQLException e){
        System.out.println(e);
    }
    

三、常规操作

向数据库发送SQL查询语句

try {Statement sql=con.createStatement();
}
catch(SQLException e) {}
处理查询结果,返回一个ResultSet对象

ResultSet rs = sql.executeQuery{"SELCET * FROM student");
关闭链接

con.close();

四、条件与排序查询

一般格式

select 字段 from 表名 where 条件
字段和固定值比较

select name from mess where name = ''
字段在某个区间范围

select * from mess where height>1.60 and height<=1.8
使用某些特殊的日期函数

select * from time_list where second(shijian)=56
用操作符like进行模式匹配

select * from mess where name like '%林%'
排序:用order by子语句对记录进行排序

selct * from mess order by height

课上内容补做

1296583-20180422232118115-1920657635.jpg

1296583-20180422232143181-1177317805.jpg

1296583-20180422232150562-2113045748.jpg

1296583-20180422232159121-1293960180.jpg

1296583-20180422232637203-1822669020.png

1296583-20180422232646426-191719323.png

11章代码解析

Example11_1:查询student数据库中的mess表的全部记录。

Example11_2:随机查询students数据库中mess表中的两条记录,首先将光标移到最后一行,然后再获取最后一行的行号,以便获取表中的记录数目

Example11_3:查询mess表中姓张,身高大于16.5,出生年份为2000或2000年之前,月份在七月份之后的学生,并按出生日期排序。

Example11_4:向mess表中插入如下两条记录:

R11,将三,2000-10-23

R10,李武,1989-7-22

Example11_5:使用预处理语句向mess表添加并查询了姓张的记录

Example11_6:将数据库名以及SQL语句传递给Query类的对象,用表格显示所查到的记录

Example11_7:将mess表中的number字段R1001的height值减少n,并将减少的n增加到字段是R1002的height上。

Example11_8:使用Derby数据库管理系统创建了名字是students的数据库,并在数据库中建立了成绩表。

转载于:https://www.cnblogs.com/gstgst/p/8910983.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值