Hello
I am trying to insert some data into a sql server i have but it seems like I'm formating the information wrong. This is what i have so far.

product id = int;
type = string;
watt = float;
volts = float;

String query = "INSERT INTO GoodCustomer(Product ID, Type, Watt, Volts) VALUES(+obj.getProductId()+,'"+obj.getType()+"','"+obj.getWatt()+"','"+obj.getVolts()+"')");

It looks like obj.getProductId() should not be inside the quotes - it's not part of a string literal, it's an expression you want evaluated.

hai slygoth,

try to change the statement formating from this

String query = "INSERT INTO GoodCustomer(Product ID, Type, Watt, Volts) VALUES(+obj.getProductId()+,'"+obj.getType()+"','"+obj.ge####t()+"','"+obj.getVolts()+"')");

to this

String query = "INSERT INTO GoodCustomer(Product ID, Type, Watt, Volts) VALUES("+obj.getProductId()+",'"+obj.getType()+"','"+obj.ge####t()+"','"+obj.getVolts()+"')");

i think you missed to give " " quotation marks at the start and end of +obj.getProductId()+

let me know the status

happy coding

Radhakrishna.p: how exactly is this answer different then the one given yesterday?

hai stultuske

when we print the sql statement at console before executing

i thought it prints like as follows (what he has given in his first)

output might be:

INSERT INTO GoodCustomer(Product ID, Type, Watt, Volts) VALUES(+obj.getProductId()+,'type_value_here','ge####t_value_here','volts_value_here')

but +obj.getProductId()+ remains the same

thats the reason i left that value as a expression evaluated value as JamesCherrill said

please have a clean look once in changed sql statement in my post

i haven't placed any single quotes which declares obj.getProductId() as a string literal in my post

thats it

my apologies to all of you if i mislead the response

any comments are appreciated

no, it wasn't misleading, but you basically just repeated what JamesCherrill said. so, my question:

how exactly is this answer different then the one given yesterday?

was more asking: why did you repeat James' answer? it doesn't really add new info to the mix.

Thanks guys for the response. Both radhak and james gave good answers. Im still getting an error tho let me send the function i have.

    public int  insertlighting(lighting obj)
    {
        int n;
        try
        {
            stat = con.createStatement();
            String query = "INSERT INTO GoodCustomer(Product ID, Type, Watt, Volts) VALUES("+obj.getProductId()+",'"+obj.getType()+"','"+obj.getWatt()+"','"+obj.getVolts()+"')");
            logger.info(query);
            n = stat.executeUpdate(query);
        }
        catch(SQLException ex)
        {
            logger.error(ex.getMessage());
            n=0;
        }
        return n;
    }

im getting " ; expected.
Want to write this information in the database.

You have an extra ) near the end of line 7.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.