相关疑难解决方法(0)

java.lang.ClassNotFoundException:Eclipse中的com.mysql.jdbc.Driver

代码有什么问题,调试时有很多错误.我正在编写一个单例类的代码来连接数据库mysql.

这是我的代码

package com.glomindz.mercuri.util;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MySingleTon {
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "test";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root";
    String password = "";

    private static MySingleTon myObj;   
    private Connection Con ;
    private MySingleTon() {
        System.out.println("Hello");
        Con= createConnection();
    }

    @SuppressWarnings("rawtypes")
    public Connection createConnection() {
        Connection connection = null;
        try {
            // Load the JDBC driver
            Class driver_class = Class.forName(driver);
            Driver driver = (Driver) driver_class.newInstance();
            DriverManager.registerDriver(driver);
            connection = DriverManager.getConnection(url …
Run Code Online (Sandbox Code Playgroud)

java jdbc mysql-connector

81
推荐指数
8
解决办法
38万
查看次数

标签 统计

java ×1

jdbc ×1

mysql-connector ×1