problems sending from a gui to a database

Hi again, I'm having problems adding to a database. In my gui I write the name of a product that is already in the database, then write how many items I want to sell of this product. When I press the send button it is supposed to be added to the table sales in the database that exists of 3 columns, PID, SID and amount.

I always get an error (For input String=""), and the error comes this class

elseif (input.equalsIgnoreCase("addSales"))

{

name = read.readLine();

amount = read.readLine();

try

{

int mAmount = Integer.parseInt(amount);

mAppl.addSale(name,mAmount);

}

catch(Exception e)

{

System.err.println(e.getMessage());

}}

This is a part of my GUI class

privateclass AddProductButtonListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent e){

outThread.addProduct(nameSaleField.getText(), amountField.getText());

outThread.setChoice("2");

}

}

publicclass OutputThreadextends Thread

{

PrintWriter write;

protectedstatic Socket out;

protectedstatic DataOutputStream output;

protected String choice ="";

protected String newProduct ="";

protected String newPrice ="";

protected String newAmount ="";

public OutputThread (Socket clientSocket){

out = clientSocket;

write =null;

}

publicvoid setChoice(String choice)

{

this.choice = choice;

}

publicvoid addProduct(String newProduct, String newPrice)

{

this.newProduct= newProduct;

this.newPrice = newPrice;

}

publicvoid addSales (String newProduct, String newAmount)

{

this.newProduct = newProduct;

this.newAmount = newAmount;

}

protectedstaticvoid initialize()

{

try

{

output =new DataOutputStream(out.getOutputStream());

}

catch(IOException e)

{

System.out.println(e.getMessage());

}

}

publicvoid sendData(double data)

{

try

{

output.writeDouble(data);

}

catch(IOException e)

{

System.out.println(e.getMessage());

}

}

publicvoid run(){

try

{

write =new PrintWriter(out.getOutputStream(),true);

}

catch (UnknownHostException e)

{

System.out.println(e.getMessage());

System.exit(1);

}

catch (IOException e){

System.err.println(e.getMessage());

System.exit(1);

}

try

{

BufferedReader stdIn =new BufferedReader(

new InputStreamReader(System.in));

String userInput;

while (!choice.equals(null)){

if(choice.equals("1"))

{

write.println("addProduct");

userInput = newProduct;

write.println(userInput);

userInput = newPrice;

write.println(userInput);

choice ="0";

}

elseif(choice.equals("2"))

{

write.println("addSales");

userInput = newProduct;

write.println(userInput);

userInput = newAmount;

write.println(userInput);

choice ="0";

}

elseif(choice.equals("3"))

{

write.println("getTotalValue");

choice ="0";

}

}}

catch(Exception e)

{

System.out.println(e.getMessage());

}}}

publicsynchronizedvoid addSale(String mName,int amount)throws SQLException

{

Statement stmt = con.createStatement();

int pid = 0;

ResultSet rs = stmt.executeQuery("Select PID from products where name='"+ mName +"'");

while(rs.next())

{

pid = rs.getInt("PID");

}

{

stmt.executeUpdate("insert into sales (PID, amount) VALUES (" + pid +", " + amount +")");

}}

I don't know if these codes are enough for you to see my problem, but I hope so.

[8096 byte] By [jazoa] at [2007-10-2 23:35:15]
# 1
Did find out of the problem myself,
jazoa at 2007-7-14 16:17:21 > top of Java-index,Java Essentials,Java Programming...