0

I am trying to develop a inventory management system as part of my mini project.

While I try to Insert a data to my Bill_Master Database it returning an error

java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-01858: a non-numeric character was found where a numeric was expected

       bqty=Integer.parseInt(iqty.getText());
       bamount=Float.parseFloat(famnt.getText());
       bdsc=Integer.parseInt(dsc.getText());
        bnet=Float.parseFloat(netamnt.getText());
         billid=Integer.parseInt(billn.getText());
         code=Integer.parseInt(icode.getText());
         bqty=Integer.parseInt(iqty.getText());
         rate=getRate(code);
         iamount=rate*bqty;
         amt.setText(Float.toString(iamount)); 
         total=total+iamount;


       try 
       {
           billdetailid++;  
     stmt.executeUpdate("insert into Bill_Master values('"+billid+"','"+date+"','"+cname+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");//Error Causing Line. 

Values are (1,'27-oct-2013','n/a',900.00,0.0,900.00,'Desk')

Table Structure

  1. Bill_Id (Primary Key INT ):-Stores Bill Number

  2. Bill_Date (Date): Stores Date Of Bill

  3. Customer_Name ( VARCHAR(50)): Customer Name

  4. Total_amt (NUMBER(6)) :Total Bill Amount

  5. Cash_Disc (Number(2)):Discount

  6. Grand_Total(Number(6)):Grand Total

  7. UID(VARCHAR(10)) Stores Who Generated the bill.(EMPLOYEE ID) Connection Type :ODBC

Please help to solve this issue.

4 Answers 4

1

You are putting single quotes around each of your values including bill_Id which is defined as an int. the SQL database is reading this as a string and complaining. Also (as was already pointed out) PreparedStatements make this a lot easier and more secure.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

stmt.executeUpdate("insert into Bill_Master values('"+billid+"',to_date('"+date+"', 'dd-MON-yyyy'),'"+cname+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");

Comments

0

Firstly that is one horrible way of writing SQL queries in java !!!

I am guessing you have just started learning. Please check out PreparedStatements

Data Type related bugs will become easier to debug.

Also that is not the way you write continuous string appends. Check out StringBuilder and String Buffer

Comments

0

I found the exact problem. The reason was I am trying to insert the Label instead of the text in the label. correct statement is

stmt.executeUpdate("insert into Bill_Master values('"+billid+"','"+date.getText()+"','"+cname.getText()+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.