why an update query is not working? - oracle

I have an update query in a servlet. The syntax is is correct, but when I execute the query, nothing happens. The execution stays frozen and the command never ends. Minutes later the message "ADVERTENCIA: GRIZZLY0023: Interrupting idle Thread: http-thread-pool-8080(5)." is printed every couple of seconds
I have tried with:
con.stmt.executeUpdate ("SQL");
con.rset = con.stmt.executeQuery ("SQL");
and with PreparedStatement.
This is the query:
System.out.println(""
+ " UPDATE JSP_TABLE SET "
+ " field1 = '" + request.getParameter("input1") + "',"
+ " field2= '" + request.getParameter("input2") + "',"
+ " field3= '" + request.getParameter("input3") + "',"
+ " field4= '" + request.getParameter("input4") + "',"
+ " field5= '" + request.getParameter("input5") + "',"
+ " field6= '" + request.getParameter("input6") + "',"
+ " field7= '" + request.getParameter("input7") + "',"
+ " field8= '" + indicador + " VS " + request.getParameter("input8") + "',"
+ " field9= '" + request.getParameter("input") + " al " + request.getParameter("hasta9") + "'"
+ " WHERE ID_PK = " + request.getParameter("inputPK"));
All my Statements, ResultSets and Connections are closed at the end of use.
I have a second update which works fine.
package Funciones;
import conexion.conectar;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ActualizarDinamica extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
conectar con = new conectar();
try {
/*
* TODO output your page here. You may use following sample code.
*/
con.stmt = con.conn.createStatement();
String indicador = "";
switch (Integer.parseInt(request.getParameter("indicador"))) {
case 1:
indicador = "Nivel de Servicio";
break;
case 2:
indicador = "Venta";
break;
case 3:
indicador = request.getParameter("txt_otro");
break;
case 0:
indicador = "Presencia";
break;
};
/* way 1
* con.rset = con.stmt.executeQuery(""
+ " UPDATE JSP_TABLE SET "
+ " FIELD1 = '" + request.getParameter("input1") + "',"
+ " FIELD2 = '" + request.getParameter("input2") + "',"
+ " FIELD3 = '" + request.getParameter("input3") + "',"
+ " FIELD4 = '" + request.getParameter("input4") + "',"
+ " FIELD5 = '" + request.getParameter("input5") + "',"
+ " FIELD6 = '" + request.getParameter("input6") + "',"
+ " FIELD7 = '" + request.getParameter("input7") + "',"
+ " FIELD8 = '" + indicador + " VS " + request.getParameter("input8") + "',"
+ " FIELD9 = '" + request.getParameter("input9") + " al " + request.getParameter("input10") + "'"
+ " WHERE FIELD_PK = " + request.getParameter("input11_ID"));
con.rset = con.stmt.executeQuery(""
+ " UPDATE JSP_TABLE2 SET"
+ " FIELD_DATE = TO_DATE('" + request.getParameter("input12") + " " + request.getParameter("input14") + ":" + request.getParameter("input13") + "','DD/MM/YYYY HH24:MI')"
+ " WHERE FIELD_ID = " + request.getParameter("input11_ID"));
*/
/* way 2
con.stmt.executeUpdate(""
+ " UPDATE JSP_TABLE SET "
+ " FIELD1 = '" + request.getParameter("input1") + "',"
+ " FIELD2 = '" + request.getParameter("input2") + "',"
+ " FIELD3 = '" + request.getParameter("input3") + "',"
+ " FIELD4 = '" + request.getParameter("input4") + "',"
+ " FIELD5 = '" + request.getParameter("input5") + "',"
+ " FIELD6 = '" + request.getParameter("input6") + "',"
+ " FIELD7 = '" + request.getParameter("input7") + "',"
+ " FIELD8 = '" + indicador + " VS " + request.getParameter("input8") + "',"
+ " FIELD9 = '" + request.getParameter("input9") + " al " + request.getParameter("input10") + "'"
+ " WHERE FIELD_PK = " + request.getParameter("input11_ID"));
con.stmt.executeUpdate(""
+ " UPDATE JSP_TABLE2 SET"
+ " FIELD_DATE = TO_DATE('" + request.getParameter("input12") + " " + request.getParameter("input14") + ":" + request.getParameter("input13") + "','DD/MM/YYYY HH24:MI')"
+ " WHERE FIELD_ID = " + request.getParameter("input11_ID"));
*/
//way 3
PreparedStatement updateSmallQuery = null;
PreparedStatement updateBigQuery = null;
String bigQuery=
""
+ " UPDATE JSP_TABLE SET "
+ " FIELD1 = '" + request.getParameter("input1") + "',"
+ " FIELD2 = '" + request.getParameter("input2") + "',"
+ " FIELD3 = '" + request.getParameter("input3") + "',"
+ " FIELD4 = '" + request.getParameter("input4") + "',"
+ " FIELD5 = '" + request.getParameter("input5") + "',"
+ " FIELD6 = '" + request.getParameter("input6") + "',"
+ " FIELD7 = '" + request.getParameter("input7") + "',"
+ " FIELD8 = '" + indicador + " VS " + request.getParameter("input8") + "',"
+ " FIELD9 = '" + request.getParameter("input9") + " al " + request.getParameter("input10") + "'"
+ " WHERE FIELD_PK = " + request.getParameter("input11_ID");
String smallQuery= ""
+ " UPDATE JSP_TABLE2 SET"
+ " FIELD_DATE = TO_DATE('" + request.getParameter("input12") + " " + request.getParameter("input14") + ":" + request.getParameter("input13") + "','DD/MM/YYYY HH24:MI')"
+ " WHERE FIELD_ID = " + request.getParameter("input11_ID");
try {
con.conn.setAutoCommit(false);
updateSmallQuery = con.conn.prepareStatement(smallQuery);
updateBigQuery = con.conn.prepareStatement(bigQuery);
updateBigQuery.executeUpdate();
updateSmallQuery.executeUpdate();
con.conn.commit();
} catch (SQLException e) {
System.out.println("catch!");
System.out.println(e.getMessage());
if (con != null) {
try {
System.err.print("Transaction is being rolled back");
con.conn.rollback();
} catch (SQLException excep) {
}
}
} finally {
if (updateSmallQuery != null) {
updateSmallQuery.close();
}
if (updateBigQuery != null) {
updateBigQuery .close();
}
con.conn.setAutoCommit(true);
}
response.sendRedirect("sol_env_c.jsp");
} finally {
con.conn.commit();
con.conn.close();
con.stmt.close();
out.close();
}
}
}
Hope this help to find the answer.
PD: The small one run with no problems. the big one it's the problem.
EDIT:
This is conectar()
public conectar() {
try {
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("Oracle JDBC driver loaded ok.");
conn = DriverManager.getConnection(params, user, password);
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
}
}

Bill is almost certainly correct and you just have a lock on rows you're trying to update. You mentioned that 'the syntax is correct', which suggests you might have checked it directly in the database - e.g. with SQL*Plus or SQL Developer - and have not issued a rollback (or commit) in that session. Attempting to update the same rows from your code is then hanging waiting for the locks to be released.
If you can find the session where you ran the update manually, issue a rollback in it. If you can't, you can see which sessions are holding locks with a query like:
select vs.osuser, vs.process, vs.logon_time, vs.sid, vs.serial#, vs.program,
dl.lock_type, dl.mode_held, dl.blocking_others
from dba_locks dl
left join v$session vs on vs.sid = dl.session_id
where lock_type != 'Media Recovery'
and lock_type != 'Redo Thread';
While your code is running - and hung - you can see what's blocking it with something like:
select vsw.osuser, vsw.process, vsw.logon_time, vsw.sid, vsw.program,
dw.lock_type, dw.mode_held,
vsh.osuser, vsh.process, vsh.logon_time, vsh.sid, vsh.serial#, vsh.program
from dba_waiters dw
left join v$session vsw on vsw.sid = dw.waiting_session
left join v$session vsh on vsh.sid = dw.holding_session;
Or search for other examples, e.g. this. You need privileges to query the v$ performance views, and if you don't have them you may need DBA assistance. If you can't manually rollback the lock you might need DBA help to kill the locking session anyway.
You should really pay attention to the comments about parameterising your statements, too.

Related

JPA SPEL optional List parameter

I have a JPA query with multiple joins and optional parameters , the query works fine if there is no multiple values sent in the status list parameter but if I send multiple values its giving exception as
"Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: An expression of non-boolean type specified in a context where a condition is expected, near ','.
Below is the query, could you please help
#Query(value = select distinct a.invn, a.accid, ac.accountCode, b.Fbusinesscode" +
", b.scode, i.invtype, d.dtid, d.did " +
" from INV.BINv a " +
"join READONLY.Fbusiness b on a.FbusinessId =b.FbusinessId " +
"join READONLY.Acc ac on a.accid=ac.accid " +
"join INV.Doc c on a.invid = c.invid " +
"join INV.Dstreq d on c.docid = d.docid " +
"join INV.dassoc e " +
"on d.dassocId = e.dassocId " +
"join BLNG.InvMType AS i on e.invtypeId = i.invtypeId "+
"where (?#{#requestdto.invoiceNumber } is null OR a.InvoiceEntityNumber = ?#{#requestdto.invoiceNumber}) and " +
" (?#{#requestdto.mod} is null OR i.InvTypeName = ?#{#requestdto.mod}) and " +
" (?#{#requestdto.getStatus} is null OR e.distrstttypecode in ?#{#requestdto.getStatus}) "
Something like this should do it:
#Query("select distinct a.invn, a.accid, ac.accountCode, b.Fbusinesscode" +
", b.scode, i.invtype, d.dtid, d.did " +
" from INV.BINv a " +
"join READONLY.Fbusiness b on a.FbusinessId =b.FbusinessId " +
"join READONLY.Acc ac on a.accid=ac.accid " +
"join INV.Doc c on a.invid = c.invid " +
"join INV.Dstreq d on c.docid = d.docid " +
"join INV.dassoc e " +
"on d.dassocId = e.dassocId " +
"join BLNG.InvMType AS i on e.invtypeId = i.invtypeId "+
"where (?#{#requestdto.invoiceNumber } is null OR a.InvoiceEntityNumber = ?#{#requestdto.invoiceNumber}) and " +
" (?#{#requestdto.mod} is null OR i.InvTypeName = ?#{#requestdto.mod}) and " +
" (?#{#requestdto.status?.size() ?: 0} = 0 OR e.distrstttypecode in ?#{#requestdto.status}) "
Note that in original query you specified requestdto.getStatus which should likely be just requestdto.status.
References:
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions-operator-elvis
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions-operator-safe-navigation

Trying to get only numbers when update from access database to textbox in C#

I just started using C# and I a have a textbox on a form. I want to display only numbers from ACCESS database, Like string stored in database is 12Kg but when I do update i should return only value i.e.12, I have searched but not getting any idea, I hope you can help me...
Query:
"Update Para Set PartNumber = '"+ txtPartNoL.Text + "', MacID = '" + cmb.SelectedValue.ToString() + "'"+" Para1 = '" + txtPara1L.Text + "', PType1 = '" + lblLPara1.Text + "'," + " val(LabourPara.Para4) = '" + txtPara4L.Text + "', PType4 = '" + lblLPara4.Text + "'," + " Qty = '" + txtQtyL.Text + "', PF = '" + txtPFL.Text + "', SF = '" + txtSFL.Text + "'," + " Amount = '" + txtAmt.Text + "'" + " WHERE QoNumber = '" + txtNo.Text + "' AND PartNumber = '" + txtPartNo.Text + "'";
You are updating everything as text, which can't be true for at least quantity and amount, so try:
sql = "Update Para Set PartNumber = '"+ txtPartNoL.Text + "', MacID = '" + cmb.SelectedValue.ToString() + "' " +
"Para1 = '" + txtPara1L.Text + "', PType1 = '" + lblLPara1.Text + "', " +
"LabourPara.Para4 = " + Val(txtPara4L.Text) + ", PType4 = '" + lblLPara4.Text + "', " +
"Qty = " + txtQtyL.Text + ", PF = '" + txtPFL.Text + "', SF = '" + txtSFL.Text + "', " +
"Amount = " + txtAmt.Text + " " +
"WHERE QoNumber = " + txtNo.Text + " AND PartNumber = '" + txtPartNo.Text + "'";
However, avoid this concatenating mess and - asap - go and learn how to use parameters.

Spring Boot Native Query returns different Resultset when executing directly in SQL Navigator

I'm using a native query to get a specific resulset since there's a conflict when using LIMIT in JPA. When I call the method via spring-boot I get 1 row but when I execute the SQL command directly I get 5 rows. I think this is a JPA native query issue it's always returning 1 row.
#Query(value = "SELECT\n" +
" DISTINCT pt1.******\n" +
" FROM\n" +
" ***** ptvt1 \n" +
" INNER JOIN\n" +
" **** pt1 \n" +
" ON ptvt1.****** = pt1.id \n" +
" WHERE\n" +
" pt1.id IN (\n" +
" SELECT\n" +
" ptvt2.****** \n" +
" FROM\n" +
" ***** ptvt2 \n" +
" INNER JOIN\n" +
" ***** pt2 \n" +
" ON ptvt2.****** = pt2.id \n" +
" WHERE\n" +
" ptvt2.******** = ptvt1.******** \n" +
" ORDER BY\n" +
" pt2.executiondate DESC LIMIT 1 \n" +
" ) \n" +
" AND NOT EXISTS (\n" +
" SELECT\n" +
" ptvt3.* \n" +
" FROM\n" +
" ***** ptvt3 \n" +
" INNER JOIN\n" +
" ***** pt3 \n" +
" ON ptvt3.****** = pt3.id \n" +
" WHERE\n" +
" ptvt3.******** = ptvt1.******** \n" +
" AND (\n" +
" pt3.status = 'OK' \n" +
" OR pt3.status = 'CREATED' \n" +
" OR pt3.status = 'PENDING' \n" +
" OR pt3.status = 'VOID' \n" +
" ) \n" +
" )", nativeQuery = true)
List<String> find*****();

SQL query error when creating a table in PostgreSQL /SpringBoot

I am using Spring Boot and PostgreSQL to create a table in which I want to insert the latest data from another table.
I was using H2 and everything was fine but when I migrated to PostgreSQL, the error "SELECT ... FROM must be followed by a reference to the table appeared e.g. SELECT * FROM table as FOO" .
However, when modifying my query with AS, I am still having the same error.
"CREATE TABLE IF NOT EXISTS EOD AS " +
"(SELECT ID, " +
"CUSIP, " +
"NAME, " +
"ISIN, " +
"NAV, " +
"RIC, " +
"RTV," +
"VOLATILITY as volatility, " +
"CURRENCY as currency, "+
"ASK_ISSUER as ask_issuer, " +
"ASK_KECH as ask_kech, " +
"AVERAGE_SCORE as average_score, " +
"BID_ISSUER as bid_issuer, " +
"BID_KECH as bid_kech, " +
"BID_ONLY as bid_only, " +
"CREATOR as creator, " +
"DECENTER as decenter, " +
"DENOMINATION as denomination, " +
"FORCE_PUBLISH as force_publish, " +
"ISSUER_SPREAD as issuer_spread, " +
"KECH_MARGIN as kech_margin, " +
"KECH_SPREAD as kech_spread, " +
"DISTANCE_TO_BANDS_SCORE as distance_to_bands_score, " +
"DIFFERENCE_TO_LEXIFI_PRICE_SCORE as difference_to_lexifi_price_score, " +
"METRIC_C as metric_c, " +
"PRICE_EXPRESSION as price_expression, " +
"PRODUCT_TYPE as product_type, " +
"PUBLISHED as published, " +
"PUBLISHING as publishing, " +
"TIMESTAMP as timestamp " +
"FROM " +
"(" +
"SELECT * FROM RTDATABASE AS T " +
"JOIN (SELECT MAX(CONVERT(TIMESTAMP, DATETIME)) AS LATESTDATE FROM T GROUP BY ISIN)" +
") tm " +
"WHERE CONVERT(tm.TIMESTAMP, DATETIME) = tm.LATESTDATE) AS LATESTDATA;";
Any idea how to solve this issue?
Many thanks in advance !

Parameters in Crystal Reports from Visual Studio 2010

My report donĀ“t accept the parameter.
I have created a parameter with "City" name.
In my code i want to full it:
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
crystalReport.SetParameterValue("City", lblCiudad.Text);
viewer.ReportSource = crystalReport;
the problem is that the report doesnt filter with my parameter, show without it.
Solution with formula:
crystalReportViewer.SelectionFormula = "{Clientes.Nombre} = '" + nombreCliente + "' AND {Registros.Host} = '" + host + "' AND {Registros.Servicio} = '" + service + "' AND {Registros.Fecha} <= " + "DateTime(" + fF.Year.ToString() + "," + fF.Month.ToString() + "," + fF.Day.ToString() + ","+fF.Hour.ToString() + "," + fF.Minute.ToString()+","+fF.Second.ToString()+") AND {Registros.Fecha} >= " + " DateTime(" + fI.Year.ToString() + "," + fI.Month.ToString() + "," + fI.Day.ToString() + ","+fI.Hour.ToString() + "," + fI.Minute.ToString()+","+fI.Second.ToString()+")";

Resources