Domanda

String Query="insert into sms (Jobno, Mobilenumber, MStatus, ReceivedTime, AmountDeducted, Message, DoneTime)       values ("+jobnum +","+mobilenum+","+ smsstatus+",'"+ rxtimestamp+ "',"+ amt+",'"+smstxt+"','"+timedone1+"')";

Note: Through the Mysql the above query is executed successfully....

I imported all the required libraries and their respective interfaces in the program.... When i execute through java panel/ide its throwing the following errors?

Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Out of range value for column 'Mobilenumber' at row 1
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2983)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
    at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1402)
    at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1317)       

Please suggest what could be the problem...........

È stato utile?

Soluzione

The amount of value from the variable mobileNumber is more than its limit. So check the datatype you have defined in both DB and java program and verify the mobileNumber you have given to save.

Altri suggerimenti

Try to check the type, range and length of the column 'Mobilenumber' and furthermore put the inserted values into '' to avoid issues with spaces, other characters in the inserted mobilenumber (e.g. "+" or "/") and long mobile numbers. If it's a real number, MySQL should correctly convert the text into a number transparently.

i.e. the resulting code should be:

String Query="insert into sms (Jobno, Mobilenumber, MStatus, ReceivedTime, AmountDeducted, Message, DoneTime)       values ('"+jobnum +"','"+mobilenum+"','"+ smsstatus+"','"+ rxtimestamp+ "','"+ amt+"','"+smstxt+"','"+timedone1+"')";

One additional hint: always try to use prepared statements to avoid opening possibilities for SQL injection attacks.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top