I'm managing a JDBC database with Servlets/JSPs and one of the attributes I have in a table is a string which may or may not have spaces in between words. I have one JSP to display all the information and another one to edit it, on both I perform getString
to a ResultSet
and when I'm just displaying it it works fine, but on the edit JSP it only "grabs" the first word before the space and the rest of the string disappears. Here's part of the code:
PerfilUsuarioConectado.jsp (the one I use to display the data)
<%
Connection conexion = DriverManager.getConnection("jdbc:odbc:gasteizcar", "", "");
Statement set = conexion.createStatement();
ResultSet rs = set.executeQuery("SELECT * FROM Usuario WHERE correoElectronico ='" + session.getAttribute("username") + "'");
rs.next();
%>
<div id="principal">
<table border="1" align="center">
<tr>
<td> Nombre: </td>
<td> <%= rs.getString("nombre")%>
</tr>
<tr>
<td> Apellidos: </td>
<td> <%= rs.getString("apellidos")%>
</tr>
<tr>
<td> E-mail: </td>
<td> <%= rs.getString("correoElectronico")%>
</tr>
<tr>
<td> Alias: </td>
<td> <%= rs.getString("alias")%>
</tr>
<tr>
<td> Nº móvil: </td>
<td> <%= rs.getString("movil")%>
</tr>
<tr>
<td> Coche: </td>
<td> <%= rs.getString("marca") + " " + rs.getString("modelo") + " " + rs.getString("color")%>
</tr>
</table>
</div>
ModificarDatos.jsp (the one to edit the data)
<%
Connection conexion = DriverManager.getConnection("jdbc:odbc:gasteizcar", "", "");
Statement set = conexion.createStatement();
ResultSet rs = set.executeQuery("SELECT * FROM Usuario WHERE correoElectronico ='"
+ session.getAttribute("username") + "'");
int i = 0;
rs.next();
String marca = rs.getString("marca");
String modelo = rs.getString("modelo");
String color = rs.getString("color");
String movil = rs.getString("movil");
%>
<div id="principal">
<form id="datos" action="ModificarDatos" method="post">
<table border="1" align="center">
<tr>
<td> * Verificar con contraseña: </td>
<td> <input pattern="[a-zA-Z0-9 ]{3,12}" type="password" id="password" name="password" required></td>
</tr>
<tr>
<td> ** Nueva contraseña: </td>
<td> <input pattern="[a-zA-Z0-9 ]{3,12}" type="password" id="nuevaContrasenia" name="nuevaContrasenia"> </td>
</tr>
<tr>
<td> ** Repita la contraseña: </td>
<td> <input pattern="[a-zA-Z0-9 ]{3,12}" type="password" id="repContrasenia" name="repContrasenia"> </td>
</tr>
<tr>
<td> * Nº de móvil: </td>
<td> <input pattern="[0-9]{9}" type="text" name="movil" id="movil" required value=<%= movil%>> </td>
</tr>
<tr>
<td> *** Marca del coche: </td>
<td> <input type="text" name="marca" id="marca" value=<%= marca%>> </td>
</tr>
<tr>
<td> *** Modelo del coche: </td>
<td> <input type="text" name="modelo" id="modelo" value=<%= modelo%>> </td>
</tr>
<tr>
<td> *** Color: </td>
<td> <input type="text" name="color" id="color" value=<%= color%>> </td>
</tr>
</table>
</div>
<input type="button" id="bActualizar" value="Actualizar datos">
So, if anyone can tell me why does the getString
method perform differently in both situations I'd be really grateful.