請幫我找出爲什麼我總是得到這個錯誤時:NullPointerException異常試圖連接到MySQL
java.lang.NullPointerException
at TaskDAO.TaskDAO.main(TaskDAO.java:34)
注:DatebaseHelper
是使用JDBC連接到MySQL的一類。
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import TaskManagement.*;
public class TaskDAO {
DatabaseHelper help;
public static void main(String[] args) throws InstantiationException,
IllegalAccessException, ClassNotFoundException, SQLException {
TaskDAO taskDAO = new TaskDAO();
int taskID = 6;
String subject = "lau cua";
Status status = Status.Completeted;
Priority priority = Priority.High;
Float percentage = 4f;
String tableName = "tasks";
String startDate = "2012/11/11";
String dueDate = "2012/11/12";
String query = "INSERT INTO "
+ tableName
+ "(taskID,subject,status,priority,percentage,startDate,dueDate)"
+ " VALUES ('" + taskID + "'," + "'" + subject + "'," + "'"
+ status + "'," + "'" + priority + "'," + "'" + percentage
+ "'," + "'" + startDate + "'," + "'" + dueDate + "')";
taskDAO.help.executeQuery(query);
}
}
給出感謝您爲您的快速回答,我在看它也許會要求你進一步的幫忙。再次感謝你。 – user1495278