Java入门:第一次操作MySQL

根据系统安装的MySQL版本找到对应的驱动文件,笔者本机安装的是:
查看MySQL版本

Mysql驱动下载地址:MySQL Connector/J

准备好文件:
mysql-connector-java-8.0.9-rc

笔者电脑安装的IDE是IntelliJ IDEA CE,导入jar驱动文件。
执行准备好的操作MySQL数据的代码:
操作MySQL代码

MySQL数据库中的表的文件是这样的,本次实验就读取其中两列的数据。
student表

迫不及待的运行一下:
获得如下数据:

/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=61842:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/ruanfumin/Documents/LearnJava/out/production/LearnJava:/Users/ruanfumin/Documents/mysql-connector-java-8.0.9-rc.jar main
Loading class `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 driver class is generally unnecessary.
Thu Dec 13 00:14:07 CST 2018 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.
成功连接数据库
张老大	北京市海淀区
张老二	北京市昌平区
张三	湖南省永州市
李四	辽宁省阜新市
王五	福建省厦门市
王六	湖南省衡阳市
Thu Dec 13 00:14:07 CST 2018 WARN: Caught while disconnecting...

EXCEPTION STACK TRACE:



** BEGIN NESTED EXCEPTION ** 

javax.net.ssl.SSLException
MESSAGE: closing inbound before receiving peer's close_notify

STACKTRACE:

javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)
	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
	at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
	at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
	at com.mysql.cj.mysqla.io.MysqlaProtocol.quit(MysqlaProtocol.java:1261)
	at com.mysql.cj.mysqla.MysqlaSession.quit(MysqlaSession.java:314)
	at com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1950)
	at com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:740)
	at main.main(main.java:36)


** END NESTED EXCEPTION **


数据库数据成功获取

Process finished with exit code 0

证明数据读取成功!宾果~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值