I am fetching data from "1st table" and storing it into resultsset. Now I want to insert the fetched data into "2nd table"
The problem is that "2nd table" only takes int values.
I tried:
while (rs.next())
{
int g = rs.getInt(1);
}
and
int g = Integer.parseInt(rs);
but it's giving me error java.lang.NumberFormatException
for input string: "com.mysql.jdbc.ResultSet@39badcaa"
Integer.parseInt(rs.getString(1));
String sql1="SELECT Id FROM kiosk_manager WHERE Kiosk_Centre='"+Uareacode+"'";
stmt1=con.createStatement();
rs=stmt1.executeQuery(sql1);
int parseInt = 0;
while (rs.next()) { parseInt=Integer.parseInt(rs.getString(1)); }
sql="INSERT INTO consumer(KioskManager_Id)VALUES("+parseInt+")"
Your resultset is returning a String which cannot be converted to Integer
Try this:
while (rs.next()) {
String str = rs.getString("COLUMN_NAME");
int g = Integer.parseInt(str);
}
Now Insert into the Db like
insert into mytable (myintfield)values(g);
Please check also that str is not returning null string value.
if the str value is for example "SE" this will not get converted. Please print out the Value getting returned first and confirm that it is a digit although in String format;
if the Value returned is for example "2"
Just do
int myint = Integer.parseInt(str);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.