tags:

views:

89

answers:

2

Hi, my friend wants from me to write two queries for him but really I don't know ,would you please help me? also there is a table with two column (String Telephone and BIGIN Charge). the sentences that I want to write a query for that:

one: Reduce the “Charge” for all Telephone numbers starting with ‘123’ by 30. two: Update all the Telephone numbers in the table by adding a ‘02’ in front of it.

thanks.

** I use MySQL**

+2  A: 

Something like this:

 select charge - 30 from YourTable where Telephone like '123%'

or

 update YourTable set charge = charge - 30 where Telephone like '123%'

I'm in doubt whether reduce means update or select so I have added both.

 update YourTable set Telephone = '02' + Telephone

Hope it helps

klausbyskov
also I have done what you told me for adding'02' but nothing will happen!!!
Johanna
Statement stmt = null; try { stmt = conn.createStatement(); } catch (SQLException ex) { Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); } String query; query = "update customer_info set Telephone = '02' + Telephone"; try { stmt.executeUpdate(query); } catch (SQLException ex) { Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); }
Johanna
@Johanna, always remember to `commit` after any change to your database.
klausbyskov
+1  A: 

You get the null pointer exception because stmt is null. Typically, you have to create stmt by using conn.createStatement(). conn is the java.sql.Connection object.

ammoQ
sorry for editing,yes I get it thanks a lot !
Johanna