簡體   English   中英

Java.lang.ClassnotfoundException com.mysql.jdbc.Driver

[英]Java.lang.ClassnotfoundException com.mysql.jdbc.Driver

運行此程序時出現java.lang.ClassnotFoundException

import java.lang.*;
import java.sql.*;
import java.io.*;
import java.util.*;

class MysqlCon{
    public static void main(String args[]){
        try{
            Class.forName("com.mysql.jdbc.Driver");

            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sonoo","root","root");
            //here sonoo is the database name, root is the username and root is the password
            Statement stmt=con.createStatement();

            ResultSet rs=stmt.executeQuery("select * from emp");

            while(rs.next())
                System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));

            con.close();

        }catch(Exception e){ System.out.println(e);}

    }
}

SQl代碼:

create database sonoo;  
use sonoo;  
create table emp(id int(10),name varchar(40),age int(3));  

我還將類路徑設置為C:\\ Program Files \\ Java \\ jre7 \\ lib \\ ext \\ mysql-5.0.7.jar,然后還給出相同的錯誤。

我認為代碼完全正確,並且mysql.jar文件有問題。 我也從以下網站下載了這個jar文件: http : //www.java2s.com/Code/Jar/m/Downloadmysql507jar.html,並且我正在使用Mysql 5.6服務器。

1)嘗試用括號將其括起來,可能會有幫助。
“ C:\\ Program Files \\ Java \\ jre7 \\ lib \\ ext \\ mysql-5.0.7.jar”

2)另外,打開JAR(使用某些程序可以
打開ZIP文件),並確保該類在
在那里(在正確的包/目錄結構下)。

該錯誤肯定表示該課程未上
即使您認為運行時的類路徑也是如此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM