• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data truncation: Truncated incorrect DOUBLE value:

 
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i havea jsp page to registere a new user.while accepting user name & password from the jsp page.........the JDBC is throwing a below mentioned error.
Exception is ;com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'rocker'

Please help me on this.

Praveen Kumar Singh
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Exception is ;com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'rocker'


'rocker' doesn't look like a double to me.
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rocker is the user name using which i am trying to register as new user from my register.jsp
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. And what is the data type of the field you are trying to save that value into?
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(NAME CHAR(15))
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure? And are you sure you are inserting the value into that field? Can you post your code?
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my register.jsp code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>New User Register page</title>
<script language="Javascript">
function Validate() {
var fname = document.regform.fname
var mname = document.regform.mname
var lname = document.regform.lname
var uname = document.regform.uname
var pass = document.regform.pass
var confpass = document.regform.confpass
if ((fname.value==null) || (fname.value=="")) {
alert("Please Enter First Name")
fname.focus()
return false
}
if ((mname.value==null) || (mname.value=="")) {
alert("Please Enter Middle Name")
mname.focus()
return false
}
if ((lname.value==null) || (lname.value=="")) {
alert("Please Enter Last Name")
lname.focus()
return false
}
if ((uname.value==null) || (uname.value=="")) {
alert("Please Enter Username")
uname.focus()
return false
}
if ((pass.value==null) || (pass.value=="")) {
alert("Please Enter user Password")
pass.focus()
return false
}
if ((confpass.value==null) || (confpass.value=="")) {
alert("Please Enter Confirm Password")
confpass.focus()
return false
}
return true
}
</script>
</head>
<body>
<form name="regform" action="RegisterServlet" method="Post"
onSubmit="return Validate()">
<table align="center" style="background-color: ffeeff;">
<tr>
<td colspan=2 style="font-weight: bold; font-size: 20pt;"
align="center">New User Registeration</td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="fname" value=""></td>
</tr>
<tr>
<td>Middle Name</td>
<td><input type="text" name="mname" value=""></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" value=""></td>
</tr>
<tr>
<td>Login Name</td>
<td><input type="text" name="uname" value=""></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" value=""></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" name="confpass" value=""></td>
</tr>
<tr align="center">
<td><input type="submit" name="Submit" value="Save User"></td>
<td><input type="Reset" name="Reset" value=" Reset"></td>
</tr>
</table>
</form>
</body>
</html>

This is my RegisterServlet code.


import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RegisterServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
PrintWriter out = response.getWriter();
Connection connection=null;
String firstname=request.getParameter("fname");
String middlename=request.getParameter("mname");
String lastname=request.getParameter("lname");
String username=request.getParameter("uname");
String password=request.getParameter("pass");
try {
Class.forName("com.mysql.jdbc.Driver");
String URL = "jdbc:mysql://localhost:3306/webapplication";
connection = DriverManager.getConnection(URL, "root", "admin");
out.println(username);
out.println(password);
String sql = "insert into login_detail set name='"+username+"'+ password='"+password+"'";
// String sql1 = "insert into user_info set FNAME='"+firstname+"'+ MNAME='"+middlename+"' + LNAME='"+lastname+"'+ name='"+username+"'";
Statement s = connection.createStatement();
out.println(sql);
// out.println(sql1);
int i = s.executeUpdate(sql);
// int j = s.executeUpdate(sql1);
if(i>0)
{
response.sendRedirect("Record Updated sucessfully");
}
s.close();
}
catch(Exception e){
System.out.println("Exception is ;"+e);
}
}
}
 
Ranch Hand
Posts: 40
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you provide description of your login_detail/user_info tables??
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


String sql = "insert into login_detail set name='"+username+"'+ password='"+password+"'";


looks like it may just be a poor quality error message from MySQL. This would resolve to the SQL statement:


Which is invalid SQL. My guess is your use of the plus sign make MySQL think its dealing with numeric fields.

This sort of mistake is yet another reason to use PreparedStatements.
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CREATE TABLE Login_Detail(NAME CHAR(15) NOT NULL UNIQUE, PASSWORD INTEGER (10) DEFAULT NULL);
CREATE TABLE User_info(FNAME CHAR(10), MNAME CHAR(10), LNAME CHAR(10),NAME CHAR(15) NOT NULL UNIQUE);
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:


String sql = "insert into login_detail set name='"+username+"'+ password='"+password+"'";


looks like it may just be a poor quality error message from MySQL. This would resolve to the SQL statement:


Which is invalid SQL. My guess is your use of the plus sign make MySQL think its dealing with numeric fields.



Sorry but the query which you have mentioned is wrong.
 
Abhishek Ralhan
Ranch Hand
Posts: 40
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Praveen,

I am afraid but the query is "Paul Sturrock" is right.
Please check it again.
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abhishek & Paul Sturrock

insert into login_detail set name = 'username' + password='password'

The parameter which i have marked in red.. these value will not be replaced with the one i am accepting thorough jsp. this is my concern.

 
Abhishek Ralhan
Ranch Hand
Posts: 40
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Praveen,

I think you didn't get the point yet.
The SQL query you are firing is:

insert into login_detail set name = 'username' + password='password'

where '+' has no meaning..

instead the query must be like this:

insert into login_detail set name = 'username', password='password';

Hope this helps..
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i have made some changes in query & now the same is working fine.

The changes which i have made is mentioned below.

String sql = "INSERT INTO user(user,password) VALUES ('"+username+"','"+password+"' )";
String sql1 = "insert into user_info(FNAME,MNAME,LNAME, user)values('"+firstname+"','"+middlename+"','"+lastname+"','"+username+"')";


Thanks every one for Help.

Praveen Kumar Singh
reply
    Bookmark Topic Watch Topic
  • New Topic