See the code below I am getting SQL errors that my product ID is null
public void BinToDB() throws Exception
{
//Create text file objects.
FileInputStream InputBinProduct;
ObjectInputStream objGetProduct;
String ProductId_Hold;
String ProductDesc_Hold;
double QtyOnHand_Hold;
double QtyOrd_Hold;
double ExtPrice_Hold;
double UnitPrice_Hold;
ProductId_Hold = "";
ProductDesc_Hold= "";
QtyOnHand_Hold= 0.0;
QtyOrd_Hold= 0.0;
ExtPrice_Hold= 0.0;
UnitPrice_Hold= 0.0;
File Selectedfile;
String FilePath ="";
int returnVal = fc.showOpenDialog (ProductApp1.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Selectedfile = fc.getSelectedFile();
//this is where a real application would open the file.
lblMessage.setText("Opening: " + fc.getName(Selectedfile));
FilePath = (fc.getCurrentDirectory() + "\\" +
fc.getName(Selectedfile));
}
else
{
lblMessage.setText("Save command cancelled by user."
;
}
try
{
InputBinProduct = new FileInputStream(FilePath);
objGetProduct = new ObjectInputStream(InputBinProduct);
Product prdt = new Product();
ProductId_Hold =prdt.getProductID();
while (ProductId_Hold != null)
{
ProductDesc_Hold= prdt.getProductDesc();
QtyOnHand_Hold= prdt.getQtyOnHand();
QtyOrd_Hold= prdt.getQtyOrd();
UnitPrice_Hold= prdt.getUnitPrice();
ExtPrice_Hold= prdt.getExtPrice();
cmdProduct.executeUpdate("Insert Into Product "
+ "([ProductID], [ProductDesc], [QtyOnHand],[QtyOrd],[UnitPrice], [extPrice] ) "
+ "Values('"
+ ProductId_Hold + "', '"
+ ProductDesc_Hold + "', '"
+ QtyOnHand_Hold + "', '"
+ QtyOrd_Hold + "', '"
+ UnitPrice_Hold + "', '"
+ ExtPrice_Hold + "')"
;
lblMessage.setText("Binary File Import Successful!"
;
ProductId_Hold =prdt.getProductID();
}
}
catch(SQLException error)
{
lblMessage.setText("Error during Edit. " + "Error: " +
error.toString());
}
catch(IOException error)
{
lblMessage.setText("Error during Edit. " + "Error: " +
error.toString());
}
catch(Exception error)
{
lblMessage.setText("Error during Edit. " + "Error: " +
error.toString());
}
//InputBinProduct.close();
//objGetProduct.close();
rsProduct = cmdProduct.executeQuery(
"Select * from Product;"
;
loadProducts(rsProduct);
public void BinToDB() throws Exception
{
//Create text file objects.
FileInputStream InputBinProduct;
ObjectInputStream objGetProduct;
String ProductId_Hold;
String ProductDesc_Hold;
double QtyOnHand_Hold;
double QtyOrd_Hold;
double ExtPrice_Hold;
double UnitPrice_Hold;
ProductId_Hold = "";
ProductDesc_Hold= "";
QtyOnHand_Hold= 0.0;
QtyOrd_Hold= 0.0;
ExtPrice_Hold= 0.0;
UnitPrice_Hold= 0.0;
File Selectedfile;
String FilePath ="";
int returnVal = fc.showOpenDialog (ProductApp1.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Selectedfile = fc.getSelectedFile();
//this is where a real application would open the file.
lblMessage.setText("Opening: " + fc.getName(Selectedfile));
FilePath = (fc.getCurrentDirectory() + "\\" +
fc.getName(Selectedfile));
}
else
{
lblMessage.setText("Save command cancelled by user."
}
try
{
InputBinProduct = new FileInputStream(FilePath);
objGetProduct = new ObjectInputStream(InputBinProduct);
Product prdt = new Product();
ProductId_Hold =prdt.getProductID();
while (ProductId_Hold != null)
{
ProductDesc_Hold= prdt.getProductDesc();
QtyOnHand_Hold= prdt.getQtyOnHand();
QtyOrd_Hold= prdt.getQtyOrd();
UnitPrice_Hold= prdt.getUnitPrice();
ExtPrice_Hold= prdt.getExtPrice();
cmdProduct.executeUpdate("Insert Into Product "
+ "([ProductID], [ProductDesc], [QtyOnHand],[QtyOrd],[UnitPrice], [extPrice] ) "
+ "Values('"
+ ProductId_Hold + "', '"
+ ProductDesc_Hold + "', '"
+ QtyOnHand_Hold + "', '"
+ QtyOrd_Hold + "', '"
+ UnitPrice_Hold + "', '"
+ ExtPrice_Hold + "')"
lblMessage.setText("Binary File Import Successful!"
ProductId_Hold =prdt.getProductID();
}
}
catch(SQLException error)
{
lblMessage.setText("Error during Edit. " + "Error: " +
error.toString());
}
catch(IOException error)
{
lblMessage.setText("Error during Edit. " + "Error: " +
error.toString());
}
catch(Exception error)
{
lblMessage.setText("Error during Edit. " + "Error: " +
error.toString());
}
//InputBinProduct.close();
//objGetProduct.close();
rsProduct = cmdProduct.executeQuery(
"Select * from Product;"
loadProducts(rsProduct);