Error When Writing to MySQL Database

I am getting the following error message when writing to a MySQL Database:

The error message was: class bsh.EvalError (line 25): .replace ( "'" , "\\'" ) -- Attempt to invoke method replace on null value

This is the script that is running after each pattern match:

//Import the entire java.sql package
import java.sql.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

//Set up a connection and a drivermanager.
Class.forName("com.mysql.jdbc.Driver").newInstance();
      Connection conn;
      conn = DriverManager.getConnection("jdbc:mysql://" + session.getVariable("MYSQL_SERVER_URL") + ":"+session.getVariable("MYSQL_SERVER_PORT") + "/" +  session.getVariable("MYSQL_DATABASE"), session.getVariable("MYSQL_SERVER_USER"), session.getVariable("MYSQL_SERVER_PASSWORD"));

// Function to generate the date
String getDateTime()
{
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
return dateFormat.format(date);
}

//Set extracted variables to local variables.
//Depending on when your script is executed
// you may have variables in session scope
// and others as dataRecords.
value1 = "VALUE1";
value2 = session.getVariable("SKU_NAME").replace("'", "\\'");
value3 = dataRecord.get("SKU_PRICE");
value4 = getDateTime();
value5 = "VALUE5";

//Create statements and run queries
// on your database.
Statement stmt = null;
stmt = conn.createStatement();

      mysqlstring="INSERT IGNORE INTO tbl_prices (site_code, sku_name, sku_price, price_date, value_five) VALUES('"+value1+"','"+ value2 + "','"+value3+"','" + value4 +"','" + value5 +"')";
      stmt.executeUpdate(mysqlstring);

//Be sure to close up your
// statements and connection.
stmt.close();
conn.close();
}

The log file shows a value of the pattern match for CARD_NAME. This exact same script is running on 2 other scrapes with no issues, but fails on this one?

You are correct, it does show

You are correct, it does show that it is Null. So the question is, why?

This is in the log file:
SKU_NAME=Arrest
...other data...
+++SKU_NAME is: null

After SKU_NAME=Arrest does it

After SKU_NAME=Arrest does it show it's being set as a session variable? Looks like not, so you need to go into the token properties, and check "set as a session variable" or (if possible, the preferred way) get it from the dataRecord. Instead of session.getv("SKU_NAME") use dataRecord.get("SKU_NAME")

That seemed to take care of

That seemed to take care of the problem, thanks!

It seems pretty clear that

It seems pretty clear that the SKU_NAME is null. If you add a line just before that line that does

session.log("+++SKU_NAME is: " + session.getVariable("SKU_NAME"));
value2 = session.getVariable("SKU_NAME").replace("'", "\'");

So you can verify.