java数据库连接(JDBC)

 java数据库连接(JDBC)

 

步骤:

  1. 在菜单栏新建web project。
  2. 在项目中新建servlet。
  3. 将连接数据库代码在src目录下。
  4. 将mysql-connector-java-5.1.47-bin.jar解压,放到项目的:项目名\WebRoot\WEB-INF\lib目录下。
  5. 右键项目,选择Build Path中的configure build path,在library中选择Add External Jars..,选择mysql-connector-java-5.1.47-bin.jar压缩包,点击apply。
  6. 以Java Application 运行程序。

A simple jdbc project (ga6v)

常见错误:

Sat Apr 06 13:53:28 CST 2019 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.
Exception in thread "main" java.sql.SQLException: Access denied for user 'scott'@'localhost' (using password: YES)

问题:数据库用户名或密码不正确

解决方法:查看下面代码中的用户名与密码填写是否正确(加粗部分)

  Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/javabook", "scott", "tiger");


Exception in thread "main" java.sql.SQLException: Client does not support authentication protocol requested by server; consider upgrading MySQL client

问题:使用的mysql-connector-java-5.1.47-bin.jar版本和数据库版本不匹配,可能mysql-connector-java的版本太老

解决方法:下载最新的mysql-connector-java-5.1.47-bin.jar版本


Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

问题:没有在library中添加jar包

解决方法:参看“步骤”中的3-5步

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值