File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Data truncation: Truncated incorrect DOUBLE value: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Data truncation: Truncated incorrect DOUBLE value:" Watch "Data truncation: Truncated incorrect DOUBLE value:" New topic
Author

Data truncation: Truncated incorrect DOUBLE value:

Praveen Kumar Singh
Greenhorn

Joined: Oct 05, 2009
Posts: 18

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


PKS
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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


'rocker' doesn't look like a double to me.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Praveen Kumar Singh
Greenhorn

Joined: Oct 05, 2009
Posts: 18

rocker is the user name using which i am trying to register as new user from my register.jsp
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

OK. And what is the data type of the field you are trying to save that value into?
Praveen Kumar Singh
Greenhorn

Joined: Oct 05, 2009
Posts: 18

(NAME CHAR(15))
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Are you sure? And are you sure you are inserting the value into that field? Can you post your code?
Praveen Kumar Singh
Greenhorn

Joined: Oct 05, 2009
Posts: 18

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);
}
}
}
Abhishek Ralhan
Ranch Hand

Joined: Aug 01, 2010
Posts: 40

can you provide description of your login_detail/user_info tables??


-Abhishek
I came to this world on a Learner's License
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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

Joined: Oct 05, 2009
Posts: 18

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

Joined: Oct 05, 2009
Posts: 18

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

Joined: Aug 01, 2010
Posts: 40

Hi Praveen,

I am afraid but the query is "Paul Sturrock" is right.
Please check it again.
Praveen Kumar Singh
Greenhorn

Joined: Oct 05, 2009
Posts: 18

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

Joined: Aug 01, 2010
Posts: 40

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

Joined: Oct 05, 2009
Posts: 18

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
 
GeeCON Prague 2014
 
subject: Data truncation: Truncated incorrect DOUBLE value: