2013-07-18 60 views
0

我有一個Maven項目正在運行,當我嘗試運行GET調用時,它向控制檯輸出一個ClassNotFound異常,然後在頁面上給我一個空結果。我有一個動態的Web項目,我複製/粘貼的代碼,並在其上正常工作。我不知道如何調試它,因爲它看起來應該工作。爲什麼Java給了我一個ClassNotFoundException?

這裏的錯誤:

Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver0:0:0:0:0:0:0:1 - - [18/Jul/2013:21:35:19 +0000] "GET /parties HTTP/1.1" 200 87 163 163 
0:0:0:0:0:0:0:1 - - [18/Jul/2013:21:35:19 +0000] "GET /favicon.ico HTTP/1.1" 404 1329 9 9 

而這裏的代碼,它發生在哪裏:

package core; 

import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.Connection; 
import java.sql.ResultSetMetaData; 
import java.sql.Statement; 
import java.util.HashMap; 

public class DBConnection { 

    private Connection con; 
    private static Statement statement; 
    private static ResultSet resultSet; 
    public static DBConnection connection; 
    private static ResultSetMetaData meta; 
    private static HashMap<String,Party> map; 

    public Party party; 

    private DBConnection() 
    { 
     try 
     { 
      map = new HashMap<String,Party>(); 
      Class.forName("com.mysql.jdbc.Driver"); 
      con = DriverManager.getConnection(
        "jdbc:mysql://atom3.cisco.com:3306/asdf", "asdf", 
        "asdf"); 
      statement = con.createStatement(); 
      readData(); 
     } 
     catch (Exception e) 
     { 
      System.out.print("Error: "+e); 
     } 
    } 
    public void readData() 
    { 
     try 
     { 
      map.clear(); 
      String query = "(SELECT * FROM PureServlet)"; 
      resultSet = statement.executeQuery(query); 
      meta = resultSet.getMetaData(); 
      String columnName, value, partyName; 
      while(resultSet.next()) 
      { 
       partyName = resultSet.getString("PARTY_NAME"); 
       map.put(partyName, new Party()); //this is the map that keeps track of all parties 
       party = map.get(partyName); 
       for(int j=1;j<=meta.getColumnCount();j++) //necessary to start at j=1 because of MySQL index starting at 1 
       { 
        columnName = meta.getColumnLabel(j); 
        value = resultSet.getString(columnName); 
        party.getPartyInfo().put(columnName, value); //this is the hashmap within the party that keeps 
        //track of the individual values. The column Name = label, value is the value 
       } 
      } 
     } 
     catch (Exception e) 
     { 
      System.out.println(e); 
     } 
    } 
    public static HashMap<String,Party> getPartyCollection() 
    { 
     if(connection == null) 
     { 
      connection = new DBConnection(); 
     } 
     return map; 
    } 
} 

回答

3

需要添加的依賴。我發誓之前發過誓,一定是意外刪除了它。

<dependency> 
<groupId>mysql</groupId> 
<artifactId>mysql-connector-java</artifactId> 
<version>5.1.6</version> 

+1

這是我編輯到我的答案,我沒有看到你的答案,而編輯:) –

0

JAR文件(ojdbc6.jar)中缺少lib目錄。
下載並放在lib目錄中,然後重試。

相關問題