Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with loading Serialized input file into a Database

Status
Not open for further replies.

simdan42

Programmer
Jul 17, 2002
118
US
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);
 
If your going to build SQL statements dynamically build them into a java.lang.String object so you can log it before executing it, or log it in the exception handler. I prefer to use java.sql.PreparedStatement

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top