CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Español

 Control Transaccional - JDBC

Print topic Send  topic

Author Message
saamondino

Posts: 33
Posted: 05/19/2009, 11:30 AM


En el Boton de mi Formulario, Envents->Server->On Click-Custom Code, Yo escribí el Sgte. codigo:

String pasos = "0<br>";
int retorno = 0;

//--- Open Connection ----
JDBCConnection conn = JDBCConnectionFactory.getJDBCConnection("ConPRUEBAS");
String sql = "";
String id_cabexp = Utils.convertToString(e.getPage().getRecord("VARIOS").getControl("ID_CAB_EXP").getFormattedValue());

//----- Borro el DET_REG_EXP -------
sql = "DELETE FROM TRB_DET_INF WHERE TRB_CAB_EXP_ID = '" + id_cabexp + "'";
pasos += " 1d " + sql + "<br>";
retorno = conn.executeUpdate(sql);
if (retorno <= 0) {
Utils.printFatalError(" -->> Error !!! = " + pasos, e.getPage().getResponse());
}
//----- FIN Borro el DET_REG_EXP -------

//--- Borro TRB_VEHICULO ---
sql = "DELETE FROM TRB_VEHICULO WHERE TRB_CAB_EXP_ID = '" + id_cabexp + "'";
pasos += " 2d " + sql + "<br>";
retorno = conn.executeUpdate(sql);
if (retorno <= 0) {
Utils.printFatalError(" -->> Error !!! = " + pasos, e.getPage().getResponse());
}
//--- FIN Borro TRB_VEHICULO ---


//----- Borro el TRB_PASOS -------
sql = "DELETE FROM TRB_PASOS WHERE ID_CAB_EXP_1_2 = '" + id_cabexp + "'";
pasos += " 7d " + sql + "<br>";
retorno = conn.executeUpdate(sql);
if (retorno <= 0) {
Utils.printFatalError(" -->> Error !!! = " + pasos, e.getPage().getResponse());
}
//--- FIN Borro TRB_PASOS ---

...

// INSERT, UPDATE, .....

...

// --- CLose Connection ---
conn.closeConnection();


Esto corre bien.

Ahora, Yo modifico el Código, incluyendo un control transaccional. Si falla un delete, insert o update, la transaccion se deshace, se ejecuta un rollback .

La base de datos que uso es Oracle 10G. El JDBC, fué bajado del sitio oficial de Oracle, Yo leí que debo usar este metodo :

conn.setAutoCommit(false);

para desactivar el autocommit y

conn.setAutoCommit(true);

para activarlo, por default es conn.setAutoCommit(true);

pero..., pero el metodo NO EXISTE en la clase JDBCConnection.



Entonces, yo escribí este código:

DBConnectionManager DBM;
Connection conn = null;

Statement stmt = null;
ResultSet rs = null;

try {
DBM = DBConnectionManager.getInstance();
conn = DBM.getConnection("ConPRUEBAS");

stmt = conn.createStatement();
conn.setAutoCommit(false);
String sql = "";
String id_cabexp = Utils.convertToString(e.getPage().getRecord("VARIOS").getControl("ID_CAB_EXP").getFormattedValue());

//----- Borro el DET_REG_EXP -------
sql = "DELETE FROM TRB_DET_INF WHERE TRB_CAB_EXP_ID = '" + id_cabexp + "'";
pasos += " 1d " + sql + "<br>";
retorno = conn.executeUpdate(sql);
if (retorno <= 0) {
Utils.printFatalError(" -->> Error !!! = " + pasos, e.getPage().getResponse());
}
//----- FIN Borro el DET_REG_EXP -------

//--- Borro TRB_VEHICULO ---
sql = "DELETE FROM TRB_VEHICULO WHERE TRB_CAB_EXP_ID = '" + id_cabexp + "'";
pasos += " 2d " + sql + "<br>";
retorno = conn.executeUpdate(sql);
if (retorno <= 0) {
Utils.printFatalError(" -->> Error !!! = " + pasos, e.getPage().getResponse());
}
//--- FIN Borro TRB_VEHICULO ---


//----- Borro el TRB_PASOS -------
sql = "DELETE FROM TRB_PASOS WHERE ID_CAB_EXP_1_2 = '" + id_cabexp + "'";
pasos += " 7d " + sql + "<br>";
retorno = conn.executeUpdate(sql);
if (retorno <= 0) {
Utils.printFatalError(" -->> Error !!! = " + pasos, e.getPage().getResponse());
}
//--- FIN Borro TRB_PASOS ---

...

// INSERT, UPDATE, .....

...


conn.commit();
conn.close();
e.getPage().setRedirectString( "TRB_CAB_EXP_list.jsp" );

} catch (Exception ex) {
try {
if (conn != null) {
conn.rollback();
}
Utils.printFatalError("Database error: " + ex.getMessage() + " -> " + pasos, e.getPage().getResponse());
} catch (Exception ex2) {
Utils.printFatalError("Database error: " + ex2.getMessage() + " -> " + pasos, e.getPage().getResponse());
}
} finally {
try {
if (rs != null) {
rs = null;
}
if (stmt != null) {
stmt = null;
}
if (conn != null) {
if (conn.isClosed() == false) {
conn.close();
}
conn = null;
}
} catch (Exception ex) {
Utils.printFatalError("Database error: " + ex.getMessage() + " -> " + pasos, e.getPage().getResponse());
}
}

e... incluí en el archivo JSP <%@page import="com.codecharge.*,...,...util.cache.ICache,java.util.regex.*,java.sql.*,java.sql.DriverManager,java.sql.Connection,java.sql.SQLException"%>


Esto trabaja bien,

PERO... Yo tengo este problema, Después de apretar 5 veces el botón, me da este error:


Estado HTTP 500 -

type Informe de Excepción

mensaje

descripción El servidor encontró un error interno () que hizo que no pudiera rellenar este requerimiento.

excepción

org.apache.jasper.JasperException: Unable to create connection 'ConPRUEBAS' to the database.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

causa raíz

java.lang.RuntimeException: Unable to create connection 'ConPRUEBAS' to the database.
com.codecharge.db.PoolJDBCConnection.getConnection(PoolJDBCConnection.java:23)
com.codecharge.db.JDBCConnection.<init>(JDBCConnection.java:85)
com.codecharge.db.PoolJDBCConnection.<init>(PoolJDBCConnection.java:15)
com.codecharge.db.JDBCConnectionFactory.getJDBCConnection(JDBCConnectionFactory.java:36)
com.codecharge.db.JDBCConnectionFactory.getJDBCConnection(JDBCConnectionFactory.java:27)
com.codecharge.ListProcessor.process(ListProcessor.java:39)
com.codecharge.RecordProcessor.processList(RecordProcessor.java:125)
com.codecharge.RecordProcessor.process(RecordProcessor.java:113)
com.codecharge.PageProcessor.process(PageProcessor.java:30)
com.codecharge.PageController.process(PageController.java:184)
org.apache.jsp.modules.inftrans.TRB_005fCAB_005fEXP_005flist_jsp._jspService(TRB_005fCAB_005fEXP_005flist_jsp.java:317)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

nota La traza completa de la causa de este error se encuentra en los archivos de diario de Apache Tomcat/5.5.23.



Curiosamente :
En el proyecto, Si modifico Connection Server "ConPRUEBAS"- Edit connection -->Server, Max. number of connection is 5.

- Yo pienso que he agotado la cantidad de conexiones, Hay conexiones que no se cierran, pero, como puedo verificar esto?

Alguien, puede ayudarme?

Muchas Gracias.

Sergio.

PD: Yo Uso, Codecharge Studio 3.2.0.6, Oracle 10G, Java 1.6, Apache Tomcat 5.5.23 y S.O. Windows 2003 Server.
View profile  Send private message
matheus

Posts: 386
Posted: 06/03/2009, 2:04 PM

See

http://forums.codecharge.com/posts.php?post_id=106158
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.