美文网首页
2018-06-09(jdbc(2))

2018-06-09(jdbc(2))

作者: acebear | 来源:发表于2018-06-09 23:17 被阅读0次

    上次的jdbc加载的语句在新版的Mysql8.0.3运行会出现问题,修改为:

    Class.forName("com.mysql.cj.jdbc.Driver");

    /*  注册mysql的jdbc驱动程。报错信息:Loadingclass`com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driverclassis generally unnecessary.   */

    c=DriverManager.getConnection("jdbc:mysql://localhost:3306/jike?useSSL=false&serverTimezone=UTC","root","");

    /*    jike为数据库名称,url中如果没有设置useSSL=false和serverTimezone=UTC,连接时都会报错。报错信息:(没有设置useSSL=false)WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements
    SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate
    property is set to 'false'.You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate
    verification.(没有设置serverTimezone=UTC)The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone valueifyou want to utilize time zone support.    */

    ps:连接数据库时,确认数据库已经打开。

    事务:并发控制的基本单位。是一个操作序列,要么都执行,要么都不执行。是一个不可分割的工作单位。是数据库维护数据一致性的单位,事务结束时都能保持数据的一致性。对于编程人员来说,可把事务看作一组sql语句,这组sql语句是一个逻辑单元,是一个整体,不可分割。

    eg:银行转账,一个账户扣款,一个账户增加金额。

    开始事务:start transaction

    提交事务:commit transaction

    回滚事务:rollback transaction

    相关文章

      网友评论

          本文标题:2018-06-09(jdbc(2))

          本文链接:https://www.haomeiwen.com/subject/jejxeftx.html