0

Capture and store data in DB

asked 2012-01-30 16:53:06 +0800

maotaborda gravatar image maotaborda
33

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!

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2012-01-30 16:55:04 +0800

maotaborda gravatar image maotaborda
33

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>

link publish delete flag offensive edit

answered 2012-01-30 17:03:42 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

In this line:

stmt.setDate(5, fechaNac.value);

You are using a java.util.Date while setDate only supports java.sql.Date.

link publish delete flag offensive edit

answered 2012-01-30 19:19:36 +0800

maotaborda gravatar image maotaborda
33

As might be implemented, since I have tried several times but it still generates errors. Thanks

link publish delete flag offensive edit

answered 2012-01-30 19:32:35 +0800

maotaborda gravatar image maotaborda
33

			<![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
							}
						}
					}
				}
			]]>

link publish delete flag offensive edit

answered 2012-01-30 19:43:30 +0800

maotaborda gravatar image maotaborda
33

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 )

link publish delete flag offensive edit

answered 2012-01-31 02:17:03 +0800

RichardL gravatar image RichardL
768 4

See gekkio's comment above.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-01-30 16:53:06 +0800

Seen: 214 times

Last updated: Jan 31 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More