java - mysql空指针异常

标签 java mysql linux jdbc

我正在运行一个自动生成电子邮件的调度程序。我在 Linux 窗口中设置了 crontab 文件,当我尝试执行调度程序时,我收到此错误消息:

Exception excp conn: com.mysql.jdbc.Driver

我已经导入了所有必要的库,你可以看到我的源代码 需要紧急支持

package Hosting;
Hosting.ScheduleMessanger

public class ScheduleMessanger {

    /**
     * @param args
     */
    public static void main(String[] args) 
    {
        Statement stmt = null;
        ResultSet rset = null;
        Statement stmt1 = null;
        ResultSet rset1 = null;
        Connection conn = null;
        int i = 0;int _fesc_ = 0;int _nesc_ = 0;int _lesc_ = 0;
        String Query = "";String Query1 = "";String EmailText = "";String CustEmail = "";
        String connect_string = "jdbc:mysql://127.0.0.1/dbname?user=user&password=passw";


        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(connect_string);
        }
        catch (Exception excp)
        {
          conn = null;
          System.out.println("Exception excp conn: "+excp.getMessage());
          return;
        }

        Query = "Query goes here";
        try
        {
          stmt = conn.createStatement();
          rset = stmt.executeQuery(Query);
          while (rset.next())
          {
            EmailText = "Dear All <br>";
            EmailText = EmailText + "The complain #"+rset.getString(2)+" is still un-resolved. <br>";
            EmailText = EmailText + "This mail is being generated to take the matter in your knowledge. <br><br>";

            EmailText = EmailText + "Complain By : " + rset.getString(3) + " <br>";
            EmailText = EmailText + "Complaint Type : " + rset.getString(4) + "<br>";
            EmailText = EmailText + "Priority Level : " + rset.getString(21) + "<br>";
            EmailText = EmailText + "Problem Description : " + rset.getString(24) + "<br>";

            EmailText = EmailText+"Sincerely, <br>";

            _fesc_ = _nesc_ = _lesc_ = 0;
            CustEmail = "";
            Query1 = "Second Query";
            try
            {
              stmt1 = conn.createStatement();
              rset1 = stmt1.executeQuery(Query1);
              if (rset1.next())
              {
                _fesc_ = rset1.getInt(1);
                _nesc_ = rset1.getInt(2);
                _lesc_ = rset1.getInt(3);
              }
              rset1.close();
              stmt1.close();
            }
            catch (Exception e)
            {
              _fesc_ = _nesc_ = _lesc_ = 0;
            }

            if (_fesc_ == 0)
            {
              if (rset.getString(10).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(10) + ",";
              }
              if (rset.getString(11).length() > 1)
              {
                CustEmail = CustEmail + rset.getString(11) + ",";
              }
              if (rset.getString(12).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(12) + ",";
              }
              i = SendEmail("Complain Escalation", "First Complain Escalation", EmailText, CustEmail);
              if (i == 1) 
              {
                UpdateEscalationTable(rset.getInt(1), 1, conn);
              }
            }
            else if (_nesc_ == 0)
            {
              if (rset.getString(13).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(13) + ",";
              }
              if (rset.getString(14).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(14) + ",";
              }
              if (rset.getString(15).length() > 1)
              {
                CustEmail = CustEmail + rset.getString(15) + ",";
              }
              i = SendEmail("Complain Escalation", "Second Complain Escalation", EmailText, CustEmail);
              if (i == 1) 
              {
                UpdateEscalationTable(rset.getInt(1), 2, conn);
              }
            }
            else if (_lesc_ == 0)
            {
              if (rset.getString(16).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(16) + ",";
              }
              if (rset.getString(17).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(17) + ",";
              }
              if (rset.getString(18).length() > 1) 
              {
                CustEmail = CustEmail + rset.getString(18) + ",";
              }
              i = SendEmail("Complain Escalation", "Final Complain Escalation", EmailText, CustEmail);
              if (i == 1) 
              {
                UpdateEscalationTable(rset.getInt(1), 3, conn);
              }
            }
          }
          rset.close();
          stmt.close();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }

    }

}

    enter code here

最佳答案

您在类路径中错过了 mysql jdbc 连接器。

关于java - mysql空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28585840/

相关文章:

java - 为什么 ArrayList 比 java 中的 HashSet 快?

java - Hadoop map-reduce 操作在写入输出时失败

android - net.sqlcipher.database.SQLiteException : file is encrypted or is not a database

linux - 如何将我的 GTK 应用程序放在桌面菜单中?

linux - 学习内核编程

java - 使用 GWT 应用程序 - 是否有解决方法可以使 IE8 正确处理/渲染长度超过 32k 的 Base64 图像 url?

java - 随机数 - 增加/减少 1

php - 如何从Mysql获取两个特定日期之间的数据

mysql - 仅从 Laravel 中的日期时间选择月份

c++ - SDL 库 PNG 支持