import java.sql.*;public class MysqlConnect{public static void main(String[] args) {System.out.println(MySQL Connect Example.);Connection conn = null;String url = jdbc:mysql://localhost:3306/;Stri...
import java.sql.*;
public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "sint";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "najeer";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
所有
我试着这个..然后
c:/>java MysqlConnect.java
C:\>java -cp .;\local\lib\mysql-connector-java-5.1.15-bin.jar MysqlConnect
MySQL Connect示例.
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/SQLClientInf
oException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.mysql.jdbc.ConnectionImpl.<clinit>(ConnectionImpl.java:270)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MysqlConnect.main(MysqlConnect.java:15)
发生此类型错误
请帮助任何人….
解决方法:
如果你可以在类路径中包含rt.jar,那么异常就会消失.
沃梦达教程
本文标题为:java – 使用mysql的jdbc连接
基础教程推荐
猜你喜欢
- Java结构型设计模式之桥接模式详细讲解 2023-05-24
- Spring Cloud Stream 高级特性使用详解 2023-05-14
- JavaWeb三大组件之一的Filter详解 2023-01-13
- 关于properties配置文件的加密方式 2023-06-23
- feign开启日志Logger.Level feignLoggerLevel()中Level爆红的解决 2023-02-05
- JSP中内建exception对象时出现500错误的解决方法 2023-08-03
- java中的OPT算法实现方式 2023-02-27
- Dubbo本地调试的几种方式总结 2023-07-01
- Mysql中备份表的多种方法 2023-07-01
- Java中Thread和Runnable创建线程的方式对比 2023-02-11