java - how to insert variable into a table in MySQL -
i know how add data table. like
string insertquery = "insert tablename (x_coord, y_coord)" +"values" +"(11.1,12.1)"; s.execute(insertquery); 11.1 , 12.1 can inserted table. given float variable
float fv = 11.1; how insert fv table?
in java, can use prepared statements this:
connection conn = null; preparedstatement pstmt = null; float floatvalue1 = 11.1; float floatvalue2 = 12.1; try { conn = getconnection(); string insertquery = "insert tablename (x_coord, y_coord)" +"values" +"(?, ?)"; pstmt = conn.preparestatement(insertquery); pstmt.setfloat(1, floatvalue1); pstmt.setfloat(2, floatvalue2); int rowcount = pstmt.executeupdate(); system.out.println("rowcount=" + rowcount); } { pstmt.close(); conn.close(); }
Comments
Post a Comment