Hi guys, what might be the cause of this exception, the reason why I did not make my methods static is because I'm running it on putty.
Here is my error: Exception in thread "main" java.lang.NoSuchMethodError: main
package NCN;
// Trying date formatting
import java.util.Locale;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.DateFormat.*; // Import names of constants
import general.stdmtd.StdMethod;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import sun.net.smtp.SmtpClient;
class Test {
OutputStreamWriter HDRosr, DTLosr, TRLosr;
StdMethod StdMthd = new StdMethod();
Connection con;
String TempString = "";
String StrCoNo = "";
String strServerName = "IP ADDRESS";
String strDBServerName = "IP ADDRESS";
String strDataBase = "NCN";
String strStatCde = "",strNCNNo = "";
String strSUPPLIER= "1";
public Test() {
}
public void main(String[] args) throws Exception {
Test test1 = new Test();
try {
test1.ConnectDB();
test1.NotifyPersonsResp("100");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void GetDays(String CoNo) throws Exception {
ResultSet rset = null;
Statement stmt;
stmt = con.createStatement();
String strQryGetDays = "";
strQryGetDays = "SELECT SUPP_COORD, SUPPLIER_1, SUPPLIER_2, QA_MANAGER " +
"FROM DELINQUENCY_DAYS " +
"WHERE IN_USE=1"; //IN_USE means that if the Databae contains more than one Del Setup then use the one where IN_USE=1
rset = stmt.executeQuery(strQryGetDays);
if (rset.next()) {
String strSUPP_COORD= rset.getString("SUPP_COORD");
String strSUPPLIER_1= rset.getString("SUPPLIER_1");
String strSUPPLIER_2= rset.getString("SUPPLIER_2");
String strQA_MANAGER= rset.getString("QA_MANAGER");
}
}
public void NotifyPersonsResp(String CoNo) throws Exception {
ResultSet rset = null, rset2 = null, rset3 = null, rset4 = null;
String EmailMsg = "";
String strDateDiff = "", strCurrEmpNo = "", strExpDateOut = "", strSiteNo = "";
String SelCurrDeptDetail = "", qryPR;
String strQryGetNCNsupplier = "", strQryGetCurrDept = "", strQryGetEmail = "";
String strQryGetNCNQAtony= "", strQryGetNCNQAcyril="";
String strQryGetNCNsupcoord= "";
Statement stmt,stmt2,stmt3,stmt4;
stmt = con.createStatement();
strQryGetNCNsupplier = "SELECT * FROM NCN WHERE (STAT_CDE BETWEEN 2 AND 6) AND CONO="+CoNo;
rset = stmt.executeQuery(strQryGetNCNsupplier);
while (rset.next()) {
strNCNNo = rset.getString("NCN_NO");
strStatCde = rset.getString("STAT_CDE");
if ((rset.getString("DATE_IN_SUPPLR") != null ) && (rset.getString("DATE_OUT_SUPPLR") == null )){
//Check Delinquency
strDateDiff = getDateDiff("DATE_IN_SUPPLR", strNCNNo);
if (rset.getString("ROOT_CAUSE")==null) { //FOR THE FIRST TIME IT GOES TO THE SUPPLIER
if ((strDateDiff!=null) && (Integer.parseInt(strDateDiff)<Integer.parseInt(strSUPPLIER))){
SelectEmailPerson(rset);
}
}
}
}
;
}
// the method below helps you when the e-mails are sent at different statuses
public void SelectEmailPerson(ResultSet NCNDetails) throws SQLException {
ResultSet rset = null;
int Status;
String qryPRsupplier = "", retMessage = "";
String qryPRsupcoord = "";
String qryPRQAtony = "";
String qryPRQAcyril = "";
Statement stmt;
stmt = con.createStatement();
Status = Integer.parseInt(strStatCde);
// This works at different statuses
switch (Status){
case 2 : {//EMAIL SUPPLY COORD
}
case 3 : {//EMAIL SUPPLIER
qryPRsupplier = "SELECT EMAIL_ADDR FROM SUPLR WHERE SUPLR_NO = '"+NCNDetails.getString("SUPLR_NO")+"' AND CONO = '"+NCNDetails.getString("CONO")+"'";
qryPRsupcoord = "SELECT EMAIL_ADDR FROM SUPLR_CORD WHERE SUPLR_CORD_EMPNO = '"+NCNDetails.getString("SUPLR_CORD_EMPNO")+"' AND SUPLR_CORD_NAME = '"+NCNDetails.getString("SUPLR_CORD_NAME")+"'";
qryPRQAtony = "SELECT EMAIL_ADDRESS FROM QA_SUGEN WHERE EMP_NO=8226";
qryPRQAcyril = "SELECT EMAIL_ADDRESS FROM QA_SUGEN WHERE EMP_NO=8354";
try {
SubmitMail("You the Supplier for NCN No : "+strNCNNo + " is deliquent.", qryPRsupplier, NCNDetails);
SubmitMail("You the Supplier Co-ordinator are delinquent for NCN "+strNCNNo + " is deliquent.", qryPRsupcoord, NCNDetails);
SubmitMail("You QA Manager() - NCN No : "+strNCNNo , qryPRQAtony, NCNDetails);
SubmitMail("You QA Manager() - NCN No : "+strNCNNo , qryPRQAcyril, NCNDetails);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
case 4 : {//EMAIL QA MANAGER
System.out.println("I am the QA!!");
break;
}
}
}
public String subDates(String DateIn, String CurrDate) throws ParseException{
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
//System.out.println(" DateIn : " + DateIn);
//System.out.println(" CurrDate : " + CurrDate);
String result="";
int dateInDay = Integer.parseInt(DateIn.substring(8));
int currDateDay = Integer.parseInt(CurrDate.substring(8));
long dateResult = (currDateDay - dateInDay) ;
result = Long.toString(dateResult);
return result;
}
//public static String getDateDiff(String DateIn, String NCNNo) throws SQLException {
public String getDateDiff(String DateIn, String NCNNo) throws SQLException {
ResultSet rsetDates = null;
String strDateDiff="",strCurrDate="";
Statement stmtDate=null;
stmtDate = con.createStatement();
//ONLY WORKS ON DBN
//String qry = "SELECT DATEDIFF(CURDATE(),"+DateIn+") AS DAYS_GONE_BY FROM NCN WHERE NCN_NO="+NCNNo;
String qry = "SELECT DATE_FORMAT("+DateIn+",'%Y-%m-%d') , CURDATE() FROM NCN WHERE NCN_NO="+NCNNo;
rsetDates = stmtDate.executeQuery(qry);
if (rsetDates.next()){
strDateDiff = rsetDates.getString(1);
strCurrDate = rsetDates.getString(2);
try {
strDateDiff = subDates(strDateDiff,strCurrDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (strDateDiff==null){
strDateDiff = "";
}
stmtDate.close();
rsetDates.close();
return strDateDiff;
}
public final void SubmitMail(String EmailMsg, String SelEmailAddr, ResultSet NCNDet)
throws Exception {
//String TempString = "";
try {
String EmailMsg2 = "", EmailMsg3 = "", EmailMsg4 = "", EmailMsg5 = "", EmailTo = "";
ResultSet rset = null;
Statement stmt = con.createStatement();
TempString = "Send Mail";
String TempString = SelEmailAddr;
rset = stmt.executeQuery(SelEmailAddr);
TempString = "Sending Email";
EmailMsg2 = "The following NCN was raised on the date: "
+ NCNDet.getString("DATE_RAISED");
EmailMsg3 = "The Initator of the NCN is: " + NCNDet.getString("RAISED_BY");
EmailMsg4 = "The NCN Details: " + strChkNull(NCNDet.getString("NCN_DETAILS"));
EmailMsg5 = "http://" + strServerName
+ "/NCN/NCN.nsf/frmMain?OpenForm&NCN_NO=" + strNCNNo +"&STAT_CDE="+strStatCde;
while (rset.next()) {
TempString = "Send Mail";
if (rset.getString(1) != null
&& !rset.getString(1).equals("")) {
EmailTo = rset.getString(1);
//for testing purposes
EmailTo = "someone@somecompany.com";
/**
System.out.println("SomeSystem@someone.com " + "\n"
+EmailTo + "\n" + EmailMsg + "\n" + EmailMsg2
+ "\n" + EmailMsg3 + "\n" + EmailMsg4 + "\n"
+ EmailMsg5);
System.out.println();
*/
//System.out.println("NOTHING HERE");
/**
System.out.println("SomeSystem@someone.com", rset
.getString(1), EmailMsg, EmailMsg2, EmailMsg3,
EmailMsg4, EmailMsg5, strServerName);
*/
//EmailTo.trim()
StdMthd.SendMail("NCNSystem@gud.co.za", EmailTo, EmailMsg, EmailMsg2, EmailMsg3,
EmailMsg4, EmailMsg5, strServerName);
/**
StdMthd.SendMail("SomeSystem@someone.com",EmailTo,
EmailMsg, EmailMsg2, EmailMsg3,
EmailMsg4, EmailMsg5, strServerName);
System.out.println("Test 8");*/
/**THIS IS THE BREAK DOWN OF THE Send mail method
* public void SendMail(
String mailfrom,
String to,
String Subject,
String msg1,
String msg2,
String msg3,
String msg4,
String MailServer)
throws Exception {
SmtpClient smtp = new SmtpClient("http://" + MailServer + "");
//assume localhost
smtp.from(mailfrom);
smtp.to(to);
PrintStream msg = smtp.startMessage();
msg.println("To: " + to); // mailers will display the To: address
msg.println("From: " + mailfrom);
//mailers will display the From: address
msg.println("Subject: " + Subject);
msg.println();
msg.println(msg1);
msg.println(msg2);
msg.println(msg3);
msg.println(msg4);
smtp.closeServer();
}
*/
}
}
rset.close();
} catch (Exception error) {
throw new Exception("Method : SubmitMail : " + TempString + error);
}
}
public void ConnectDB() throws Exception {
try {
String strPort ="portno";
String jdbcDriver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://" + strDBServerName + ":" +strPort+ "/NCN";
String account = "trrtrt";
String password = "pasword";
TempString = "Connecting to Database-NCN";
DriverManager.registerDriver((Driver) Class.forName(jdbcDriver)
.newInstance());
con = DriverManager.getConnection(url, account, password);
} catch (Exception error) {
throw new Exception(TempString + error);
}
}
public String getStrStatCde() {
return strStatCde;
}
public void setStrStatCde(String strStatCde) {
strStatCde = strStatCde;
}
public String getStrNCNNo() {
return strNCNNo;
}
public String strChkNull(String param) {
if ((param == null) || (param.equals("null")))
return "";
else
return param;
}
public void setStrNCNNo(String strNCNNo) {
strNCNNo = strNCNNo;
}
}