我有一个 Maven 项目正在运行,当我尝试运行 GET 调用时,它会在控制台上打印一个 ClassNotFound 异常,然后在页面上给我一个空结果。我有一个动态的 Web 项目,我从中复制/粘贴了代码,它可以正常工作。我不知道如何调试它,因为它看起来应该可以工作。
这是错误:
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;
}
}