-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Good morning, I have trouble saving a customer data in Table Mysql customers, especially with the capture of the date of birth and registration of the client. All variables are captured through a data entry form.
I get this error:
Sourced file: inline evaluation of: `` . . . '' : Error in method invocation: Method setDate( int, java.util.Date ) not found in class'org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement' : at Line: 48 : in file: inline evaluation of: `` import java.sql.*; import java.util.*; import javax. . . . '' : stmt .setDate ( 5 , fechaNac .value )
If anyone can help I'd appreciate it, thank you very much!
this is the code:
<zscript> <![CDATA[ import java.sql.*; import java.util.*; import javax.sql.*; import javax.naming.InitialContext; void Guardar() { DataSource ds = (DataSource) new InitialContext() .lookup("java:comp/env/jdbc/planeta-docs"); Connection conn = null; PreparedStatement stmt = null; //PreparedStatement stmt = conn.PreparedStatement(sql); Date date = new Date(0000-00-00); fechaNac.getValue(); /*java.util.Date utilDate = date.getValue(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); fechaReg.setDate (SQLDate);*/ try { conn = ds.getConnection(); //remember that we specify autocommit as false in the context.xml conn.setAutoCommit(true); stmt = conn.prepareStatement("INSERT INTO clientes values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); //Insertar lo que el usuario finalmente entro en el formulario stmt.setString(2, strNombre.value); stmt.setString(3, strApellido.value); stmt.setInt(4, cedula.value); stmt.setDate(5, fechaNac.value); // java.sql.Date date = getCurrentJavaSqlDate(); //stmt.setDate(6, fechaReg.date); //stmt.setDate(6, new java.sql.Date(myDate.getTime())); stmt.setDate(6,new java.sql.Date(dbDate.getValue().getTime())); stmt.setString(7, sexo.value); stmt.setString(8, email.value); stmt.setInt(9, telefono.value); stmt.setInt(10, celular.value); stmt.setString(11, direccion.value); stmt.setString(12, "Activo"); //stmt.executeUpdate(); int row = stmt.executeUpdate(); System.out.println(row + " row(s) affected"); stmt.close(); stmt = null; } catch (SQLException e) { conn.rollback(); //(optional log and) ignore } finally { //cleanup if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { //(optional log and) ignore } } if (conn != null) { try { conn.close(); } catch (SQLException ex) { //(optional log and) ignore } } } } ]]> </zscript>
In this line:
stmt.setDate(5, fechaNac.value);
You are using a java.util.Date while setDate only supports java.sql.Date.
As might be implemented, since I have tried several times but it still generates errors. Thanks
<![CDATA[ import java.sql.*; import java.sql.Date; import java.util.*; import javax.sql.*; import javax.naming.InitialContext; void Guardar() { DataSource ds = (DataSource) new InitialContext() .lookup("java:comp/env/jdbc/planeta-docs"); Connection conn = null; PreparedStatement stmt = null; try { conn = ds.getConnection(); //remember that we specify autocommit as false in the context.xml conn.setAutoCommit(true); stmt = conn.prepareStatement("INSERT INTO clientes values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); //Insertar lo que el usuario finalmente entro en el formulario stmt.setString(2, strNombre.value); stmt.setString(3, strApellido.value); stmt.setInt(4, cedula.value); fechaNac.getValue(); stmt.setDate(5, fechaNac.value); java.sql.Date sqlDate = new java.sql.Date(0); date = sqlDate; fechaReg.getValue(); stmt.setDate(6, fechaReg.value); stmt.setString(7, sexo.value); stmt.setString(8, email.value); stmt.setInt(9, telefono.value); stmt.setInt(10, celular.value); stmt.setString(11, direccion.value); stmt.setString(12, "Activo"); //stmt.executeUpdate(); int row = stmt.executeUpdate(); System.out.println(row + " row(s) affected"); stmt.close(); stmt = null; } catch (SQLException e) { conn.rollback(); //(optional log and) ignore } finally { //cleanup if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { //(optional log and) ignore } } if (conn != null) { try { conn.close(); } catch (SQLException ex) { //(optional log and) ignore } } } } ]]>
Error:
Sourced file: inline evaluation of: `` . . . '' : Error in method invocation: Method setString( int, java.util.Date ) not found in class'org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement' : at Line: 41 : in file: inline evaluation of: `` import java.sql.*; import java.util.*; import javax. . . . '' : stmt .setString ( 5 , fechaNac .value )
Asked: 2012-01-30 16:53:06 +0800
Seen: 214 times
Last updated: Jan 31 '12