gpt4 book ai didi

java - mysql空指针异常

转载 作者:太空宇宙 更新时间:2023-11-04 09:34:01 25 4
gpt4 key购买 nike

我正在运行一个自动生成电子邮件的调度程序。我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com