0

i am new to java.i want to insert values into my database(pgadmin) using java.i am using a PreparedStatement but everytime it is giving me an error.The problem seemed to be in the INSERT statement..please help me

public void obtaindata(){
        System.out.println("enter the data you want to insert");
        System.out.print("Product Name");
        String productname=input.nextLine();
        System.out.println("Product Price");
        Double productprice=input.nextDouble();
        Database2 database2=new Database2();
        database2.insertRecord(productname,productprice);

public void insertRecord(String productname,Double productprice){
        try{
            //using preparedstatement
            PreparedStatement stmt = con.prepareStatement("INSERT INTO  
               public.product(product_id,product_name,product_price)" + 
              "VALUES (?,?,?);"); 
            stmt.setString(1,"nextval('productid_sequence')");
            stmt.setString(2,productname);
            stmt.setDouble(3,productprice);
            stmt.executeUpdate();
            stmt.close();

        }catch(SQLException e){
            e.printStackTrace();
        }
    }

0 Answers0