Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'jdbc_app'
原因,创建数据库的时候,写错了名字,修改正确的名字即可。
错误排查2 找不到驱动
1 2 3 4 5 6 7 8 9 10 11 12
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at time20210720.jdbc.JDBCCon.main(JDBCCon.java:11) Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/java_app at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:247) at time20210720.jdbc.JDBCCon.main(JDBCCon.java:20)
项目中找不到驱动的jar包
添加jar包到项目下的lib目录,然后add to Build Path
错误排查3
1 2 3 4 5 6 7 8 9
java.lang.ClassNotFoundException: com.mysql.jdbc.Dirver at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at time20210720.jdbc.JDBCCon.main(JDBCCon.java:12) com.mysql.jdbc.JDBC4Connection@3d646c37
org.junit.runners.model.InvalidTestClassError: Invalid test class 'time20210720.jdbc.JDBCCon': 1. Method testConnetion() should not be static 2. Method testConnetion() should be public at org.junit.runners.ParentRunner.validate(ParentRunner.java:525) ......