Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot be Resolved  RSS feed

 
muhsin sabeer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following snipet of code

package umac.MeterControl.DB.Transaction;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;
import java.util.Date;

import umac.util.CommonUtil;

public class TransactionTable {

public static int insert(Connection conn , TransactionBean tb) throws SQLException {

String sqlstatement1 = "select meterID, transactionTime from Transaction";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sqlstatement1);
while(rs.next())
{
int sMeterid = rs.getInt("meterID");
Date transTime = rs.getDate("transactionTime");
System.out.println(tb.getMeterID());
System.out.println(sMeterid);
System.out.println(tb.getTransactionTime());
System.out.println(transTime);
if (tb.getMeterID() == sMeterid && tb.getTransactionTime() == transTime)
{
String sqlstatement = "insert into Exception_Transaction (meterID, fromCardID, toCardID, "
+ "meterMode, amount, cardBalance, accBalance, transactionTime, lastModifiedDate, status) "
+ "values(" + tb.getMeterID() + ", '" + tb.getFromCardID() + "', '" + tb.getToCardID()
+ "', '" + tb.getMode() + "', " + tb.getAmount() + ", " + tb.getCardBalance() + ", "
+ tb.getAccBalance() + ", " + CommonUtil.DateToSQLStr(tb.getTransactionTime())
+ ", " + CommonUtil.DateToSQLStr(tb.getLastModifiedDate()) + ", " + tb.getResult() + ")";

}
else
{
String sqlstatement = "insert into Transaction (meterID, fromCardID, toCardID, "
+ "meterMode, amount, cardBalance, accBalance, transactionTime, lastModifiedDate, status) "
+ "values(" + tb.getMeterID() + ", '" + tb.getFromCardID() + "', '" + tb.getToCardID()
+ "', '" + tb.getMode() + "', " + tb.getAmount() + ", " + tb.getCardBalance() + ", "
+ tb.getAccBalance() + ", " + CommonUtil.DateToSQLStr(tb.getTransactionTime())
+ ", " + CommonUtil.DateToSQLStr(tb.getLastModifiedDate()) + ", " + tb.getResult() + ")";

}

int result = stmt.executeUpdate(SQLSTATEMENT);
return result;

}
stmt.close();

}
}

Now when i compile, i get a error message saying the "sqlstatement cannot be resolved"(the one which i have written in BOLD letters)

Can any one of you help me on this?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Strign variable is not visible outside the if/else statement.

Declare "String sqlstatement" out of your if/else statement, and call:
int result = stmt.executeUpdate(sqlstatement);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!