How to re-issue an SQL query in java code in deadlock situation ?
Hi all..
I have a java application (in Struts) which is running on JBoss 4.0.1 server. The database is MySql 6.0. It is an
application made to be used among multiusers. The background operating system is Windows Vista.
Now a days i am facing a peculiar problem due to which the further things go wrong. I am getting following error :
com.mysql.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
I searched over forums and i got response as restart the transaction in deadlock.
In my java code it is a delete query where i get such exception when multiple users are accessing the application. What i tried for time being is as follows :
Statement stmt = null;
String temp = null;
Connection conn = null;
String sUserID =(String) session.getAttribute("username")
try
conn = DBConnection.getJndiConnection();
stmt = conn.createStatement();
temp = "Delete FROM temptable where Login ='"+sUserID+"'";
System.out.println("QUERY:"+temp);
int rowCount = stmt.executeUpdate(temp);
System.out.println("Rows affected in try ="+rowCount+" for user :"+sUserID);
// in catch i re-issue the delete query in deadlock..
catch (com.mysql.jdbc.exceptions.MySQLTransactionRollbackException ne)
System.out.println("Error ....Deadlock occured for user: "+sUserID);
ne.printStackTrace();
try
int rowCount = s.executeUpdate(temp);
System.out.println("Rows affected in catch ="+rowCount+" for user :"+sUserID);
catch (Exception e)
System.out.println("Exception again after restarting transaction..with user :"+sUserID);
e.printStackTrace();
(all necessary imports are present in code)
Here i am properly establishing the database connection with the help of other class DBConnection. As most of the forum insisted to re-issue the transaction, i have tried upto one level with above code. But still the problem is just partially solved.
How can i write my code so that every time if there is MySQLTransactionRollbackException , then the delete query should be re-issued again and again untill the transaction is complete.
Can i use GOTO statement ? or is it bad programming practice?
What are the other possible ways ??
Can someone please help in this regard ??
Thanks in advance..
Regards
Prasad
Hi all
i am new for these kind of databae transaction operation i am getting following error
/resetattendancedata.dqlMessage: Deadlock found when trying to get lock; Try restarting transaction, message from server: "Lock wait timeout exceeded; try restarting transaction" Cause: null Error Message: Deadlock found when trying to get lock; Try restarting transaction, message from server: "Lock wait timeout exceeded; try restarting transaction" Cause: null Error code: 1205 Error state: 41000 java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction, message from server: "Lock wait timeout exceeded; try restarting transaction"
Here is my code i have written
if(movements.equalsIgnoreCase("ON"))
System.out.println("Movement");
if(submovements.equalsIgnoreCase("statusonly"))
query="";
query="UPDATE TRNMOVEMENT SET PROCESSED='N',STATUSPUT='N',ATTDATE=NULL,TIMEDIFF='' "
+"WHERE ATTDATE BETWEEN '"datefrom1"' AND '"dateto"' AND EMPID IN "
+"(SELECT SYSEMPID "
+"FROM (((MSTPERSONALDETAILS PD LEFT JOIN MSTCATEGORY CAT ON PD.CATEGCODE=CAT.SYSCATEGCODE)"
+"LEFT JOIN MSTUNITDETAILS U ON PD.UNITCODE=U.SYSUNITCODE) "
+"LEFT JOIN MSTDESIGNATION DES ON PD.DESIGCODE=DES.SYSDESIGCODE) "
+"LEFT JOIN MSTDEPARTMENT DEP ON PD.DEPTCODE=DEP.SYSDEPTCODE "strFltrString" ) ";
leaveStmt.executeUpdate(query);
leaveStmt.executeUpdate("commit");
else if(submovements.equalsIgnoreCase("flagstatus"))
query="";
query="UPDATE TRNMOVEMENT SET PROCESSED='N',STATUSPUT='N',ATTDATE=NULL,FLAG='',TIMEDIFF='',BREAK='N'WHERE ATTDATE BETWEEN '"datefrom1"' AND '"dateto"' AND EMPID IN (SELECT SYSEMPID FROM(((MSTPERSONALDETAILS PD LEFT JOIN MSTCATEGORY CAT ON PD.CATEGCODE=CAT.SYSCATEGCODE) LEFT JOIN MSTUNITDETAILS U ON PD.UNITCODE=U.SYSUNITCODE) LEFT JOIN MSTDESIGNATION DES ON PD.DESIGCODE=DES.SYSDESIGCODE) LEFT JOIN MSTDEPARTMENT DEP ON PD.DEPTCODE=DEP.SYSDEPTCODE WHERE EMPID IS NOT NULL "strFltrString" ) ";
leaveStmt.executeUpdate(query);
synchronized(leaveStmt)
//leaveStmt1.executeUpdate("set TRANSACTION ISOLATION LEVEL REPEATABLE READ"); // setting transaction level using SQL
// leaveStmt1.executeUpdate("start transaction"); // Starting a transaction using SQL
query1="DELETE FROM TRNDAILYATTENDANCE WHERE ATTDATE BETWEEN '"datefrom1"' AND '"dateto"' AND EMPID IN (SELECT SYSEMPID FROM (((MSTPERSONALDETAILS PD "
+"LEFT JOIN MSTCATEGORY CAT ON PD.CATEGCODE=CAT.SYSCATEGCODE) LEFT JOIN MSTUNITDETAILS U ON PD.UNITCODE=U.SYSUNITCODE) LEFT JOIN MSTDESIGNATION DES ON PD.DESIGCODE = DES.SYSDESIGCODE )LEFT JOIN MSTDEPARTMENT DEP ON PD.DEPTCODE=DEP.SYSDEPTCODE WHERE EMPID IS NOT NULL "strFltrString" )";
//leaveStmt.addBatch(query1);
leaveStmt.executeUpdate(query1);
synchronized(leaveStmt)
query2="UPDATE TRNLEAVEAPPLICATION SET TAKENTOATT='N' WHERE '"datefrom1"' BETWEEN FROMDATE AND "
+"TODATE AND '"dateto"' BETWEEN FROMDATE AND TODATE AND EMPID IN (SELECT SYSEMPID FROM (((MSTPERSONALDETAILS PD LEFT JOIN MSTCATEGORY CAT ON "
+"PD.CATEGCODE=CAT.SYSCATEGCODE) LEFT JOIN MSTUNITDETAILS U ON PD.UNITCODE=U.SYSUNITCODE) LEFT JOIN "
+"MSTDESIGNATION DES ON PD.DESIGCODE=DES.SYSDESIGCODE) LEFT JOIN MSTDEPARTMENT DEP ON PD.DEPTCODE=DEP.SYSDEPTCODE WHERE EMPID IS NOT NULL "+strFltrString +") ";
//leaveStmt.addBatch(query2);
//leaveStmt.executeBatch();
leaveStmt.executeUpdate(query2);
//} // end of for loop
else
leaveStmt.executeUpdate("commit");
Please Solve my problem for this error thanks in advance........
Similar Messages
-
How i can execute the sql query in java code
I already have sql query in jave plateform i need to execute this code how i can do that. i have unix env and with oracle database. should i just run this query in my sqlplus. this file has extention .java. thanks
you can create a project in JDeveloper add the java file to it, add the Oracle JDBC library to the project properties and then hit the run button.
-
How to use sql query in java ?
i don't know how to use sql query in java code.
who can give me some advice?
thankshttp://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/
-
How to compare result from sql query with data writen in html input tag?
how to compare result
from sql query with data
writen in html input tag?
I need to compare
user and password in html form
with all user and password in database
how to do this?
or put the resulr from sql query
in array
please help me?Hi dejani
first get the user name and password enter by the user
using
String sUsername=request.getParameter("name of the textfield");
String sPassword=request.getParameter("name of the textfield");
after executeQuery() statement
int exist=0;
while(rs.next())
String sUserId= rs.getString("username");
String sPass_wd= rs.getString("password");
if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
exist=1;
if(exist==1)
out.println("user exist");
else
out.println("not exist"); -
Re: How to converting from PL/SQL query to T-SQL query
How to converting from PL/SQL query to T-SQL query... Its Urgent
Download the
SQL Server Migration Assistant for Oracle. It will convert whole Oracle databases, or single queries or PL/SQL stored procedures.
With caution that If your database is using Collation which is case sensitive SSMA will not work.SSMA doesnt guarantees 100% for conversion of Queries/stored proc /database if it fails to do so for some queries you will have to do it manually.
But you can try
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
How to isolate the Sql Statement from Java Code
Hi
I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
Suppose the developer has these four Statements
Select ename,empno,sal,job from emp;
select empno,ename,mgr from emp;
select deptno,dname from dept;
select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
Can Anybody guide me how to write this Stored type of Store procedure.
Thankshttp://www.google.com/search?q=java+windows+registry
Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this. -
SQL Fails when a division is included in query (in Java Code)
Not sure this is the correct Forum to as this:
Running Oracle 10g R2 on XP/Vista
I have a query that contains a division operation (y.value as x.value/z.value) runs in SQLPlus and The NetBeans 6.5.1 Query Editor OK but when I insert it into Java (1.6) code (abc.java) it fails.
I tried to escape the "\" operator <whatever> (\/) and that dows not work either.
Can someone help me with this
Thanks
J.Thanks ... You got me on that one... should havr provided the query upfront..
However, I thought it was more likely that there was something one always has to do to get "functions" to run inside a query inside Java code
Here's the query plus some code
Pls note the: round(((x.VALUE/226672)*100),2) as Percentage
r_dayEBOMDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{Page1.r_dayEBOMRowSet}"));
r_dayEBOMRowSet.setDataSourceName("java:comp/env/jdbc/ABC_Oracle");
r_dayEBOMRowSet.setCommand("WITH vals AS (SELECT date_day, value, site_datatype_id FROM r_day WHERE site_datatype_id = '1234' AND date_day > date_day - 367) SELECT x.date_day,x.VALUE,y.date_day,y.VALUE AS valuem1w,z.date_day,z.VALUE AS valuem1y,round(((x.VALUE/226672)*100),2) as Percentage FROM vals x, vals y, vals z WHERE y.date_day(+) = x.date_day - 7 AND z.date_day(+) = ADD_MONTHS (x.date_day,-12) AND y.site_datatype_id(+) = x.site_datatype_id AND z.site_datatype_id(+) = x.site_datatype_id AND x.date_day = TO_DATE('16-Feb-2010','DD-MON-YYYY')");
r_dayEBOMRowSet.setTableName("R_DAY");
Again, this works fine inside of SqlPlus and NetBeans Query Editor
not in Java code thought.
Thanks
J. -
How do I produce an excel file using java code
How do i produce an excel file using java code.
If it is possible would ne one have ne source code as an example.
I have tried looking up information on outputing the information to a *.csv file but unfortunality i have had no luck in finding any information. To be exact ne source code.
Thanks
LeeThat's what I use and I'd be the first to admit that it's very messy. But it works. Go use Google and see what else you can find.
-
Convert SQL statements to JAVA Code ?
Using SQL queries Can I convert SQL statements to JAVA Code ?
Edited by: user11238895 on Jun 7, 2009 10:54 PM
Edited by: user11238895 on Jun 7, 2009 11:12 PMMe very new to Oracle.
can we convert SQL Queries to JAVA Code using simple built in SQL queries ?
Which SWISS SQL Tool does [Converting SQL Queries to JAVA Code] -
How doest jdk docs help as in writing java code?
hi i wonder how does jdk docs help as in writing java code because if i google a java code the jdk docs always becomes the result of my search but in my experience jdk docs never helps me.
is there any one know how to use jdk docs? and how to get the code from there.
im telling about jdk docs from here http://download.oracle.com/javase/1.4.2/docs/api/
cross posted from http://www.thenewboston.com/forum/viewtopic.php?f=119&t=13778
Edited by: 871484 on Jul 18, 2011 4:18 PM871484 wrote:
ok can any one give me example how to use jdk docs? for example this code
Your question still does not make any sense, and you still haven't clarified what you're not understanding.
However, if you think that just by reading the API docs, with no other training or study, that you will be able to write that code, then you are seriously misunderstanding the purpose of the docs.
Obviously English is not your native language. You grew up speaking some other language at home and with your friends, and at some point in school or as private study, you started to learn English. You learned about the grammar and the alphabet and pronunciation, sentence structure, word order, etc. Now you have the basics of how the language works, and you know some words. When you want to learn new words to fit into the structure you have learned, you use a dictionary.
If you didn't study the grammar, sentence structure, etc., and just said, "I want to learn English. I will look at a dicationary," clearly that would not work.
Right?
So, since you now understand and agree with the English example, let me state something that I hope is obvious to you by now: The API docs are your dictionary. They are not a substitute for learning the language basics.
Furthermore, once you know the language basics in English and have your dictionary, you still won't know how to write a resume (which you may know as a CV). You will look at examples and perhaps take a course on resume (CV) writing. Just reading a dictionary won't help you write a resume(CV). Similarly, if you know some Java basics, you can't learn how to write a Swing app just by reading the Javadocs. You'll look at tutorials and examples. Then, once you know the basic structure of a Swing app, you'll look to the javadocs for more details about more kinds of GUI classes--different buttons and windows and panes and panels and layout managers, etc. -
How to send SMS ( Short Message Service ) from java code
Hi
How to send SMS ( Short Message Service ) from java code.
Thanks
GauravDo you need to receive SMS? If you need to receive SMS, you will need to host your own GSM device or modem so that people can send you SMS.
If not, you can just use internet SMS gateways like clickatell as mentioned above will do the work, and post to them by HTTP, XML or email. The cost is about 6-8 cents per SMS. There are cheaper services, but not always reliable. If you need to host your own GSM device, you can use software like http://www.kannel.org (GPL Open Source) or http://www.visualgsm.com. Alternatively, you may obtain a shortcode from your Telco - but these come with monthly subscription of maybe one or two hundreds.
Regards,
Joshua
<SMS Gateway>@Expert -
Issue with SQL Query with Presentation Variable as Data Source in BI Publisher
Hello All
I have an issue with creating BIP report based on OBIEE reports which is done using direct SQL. There is this one report in OBIEE dashboard, which is written using direct SQL. To create the pixel perfect version of this report, I am creating BIP data model using SQL Query as data source. The physical query that is used to create OBIEE report has several presentation variables in its where clause.
select TILE4,max(APPTS), 'Top Count' from
SELECT c5 as division,nvl(DECODE (C2,0,0,(c1/c2)*100),0) AS APPTS,NTILE (4) OVER ( ORDER BY nvl(DECODE (C2,0,0,(c1/c2)*100),0)) AS TILE4,
c4 as dept,c6 as month FROM
select sum(case when T6736.TYPE = 'ATM' then T7608.COUNT end ) as c1,
sum(case when T6736.TYPE in ('Call Center', 'LSM') then T7608.CONFIRMED_COUNT end ) as c2,
T802.NAME_LEVEL_6 as c3,
T802.NAME_LEVEL_1 as c4,
T6172.CALENDARMONTHNAMEANDYEAR as c5,
T6172.CALENDARMONTHNUMBERINYEAR as c6,
T802.DEPT_CODE as c7
from
DW_date_DIM T6736 /* z_dim_date */ ,
DW_MONTH_DIM T6172 /* z_dim_month */ ,
DW_GEOS_DIM T802 /* z_dim_dept_geo_hierarchy */ ,
DW_Count_MONTH_AGG T7608 /* z_fact_Count_month_agg */
where ( T802.DEpt_CODE = T7608.DEPT_CODE and T802.NAME_LEVEL_1 = '@{PV_D}{RSD}'
and T802.CALENDARMONTHNAMEANDYEAR = 'July 2013'
and T6172.MONTH_KEY = T7608.MONTH_KEY and T6736.DATE_KEY = T7608.DATE_KEY
and (T6172.CALENDARMONTHNUMBERINYEAR between substr('@{Month_Start}',0,6) and substr('@{Month_END}',8,13))
and (T6736.TYPE in ('Call Center', 'LSM')) )
group by T802.DEPT_CODE, T802.NAME_LEVEL_6, T802.NAME_LEVEL_1, T6172.CALENDARMONTHNAMEANDYEAR, T6172.CALENDARMONTHNUMBERINYEAR
order by c4, c3, c6, c7, c5
))where tile4=3 group by tile4
When I try to view data after creating the data set, I get the following error:
Failed to load XML
XML Parsing Error: mismatched tag. Expected: . Location: http://172.20.17.142:9704/xmlpserver/servlet/xdo Line Number 2, Column 580:
Now when I remove those Presention variables (@{PV1}, @{PV2}) in the query with some hard coded values, it is working fine.
So I know it is the PV that's causing this error.
How can I work around it?
There is no way to create equivalent report without using the direct sql..
Thanks in advanceI have found a solution to this problem after some more investigation. PowerQuery does not support to use SQL statement as source for Teradata (possibly same for other sources as well). This is "by design" according to Microsoft. Hence the problem
is not because different PowerQuery versions as mentioned above. When designing the query in PowerQuery in Excel make sure to use the interface/navigation to create the query/select tables and NOT a SQL statement. The SQL statement as source works fine on
a client machine but not when scheduling it in Power BI in the cloud. I would like to see that the functionality within PowerQuery and Excel should be the same as in Power BI in the cloud. And at least when there is a difference it would be nice with documentation
or more descriptive errors.
//Jonas -
How to write a SQL query in Java
Hi, I'm writing a program that pulls all data from the database with a simple "SELECT * FROM [TABLE NAME]. The problem is that I don't know how to set it up properly. My code will only connect to the database but not execute the query. Please help.
{code}import java.sql.*;
import java.util.Properties;
import java.sql.*;
public class DatabaseSelect {
public static void main(String[] args) {
System.out.println("Connected to the database!");
Connection conn = null;
String url = "jdbc:oracle://localhost:1571/";
String dbName = "jdbc";
String driver = "com.oracle.jdbc.Driver";
String userName = "HR";
String password = "database";
String query = "SELECT * FROM HR";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
} catch (Exception e) {
e.printStackTrace();
}{code}pbsacct_1 wrote:
I added it between my System.out statement and the catch exception. This is what I put, but I'm getting the same result. I looks like a lot of errors. The only thing that prints is the "Connected to database".
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet srs = stmt.executeQuery("SELECT * FROM HR");Here is what displays in the console.
Connected to the database!
java.lang.ClassNotFoundException: com.oracle.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at Discussion10.DatabaseSelect.main(DatabaseSelect.java:26)You are not connecting.
Because you aren't even loading the driver.
To be honest if you can't decipher a stack trace with "java.lang.ClassNotFoundException" on your own you are not ready for JDBC anyway. -
How to set fetchsize of sql Query when using Database Adapter.
Hi All,
I am using DatabaseAdapter to connect to database and retriving huge amount of data.For improvement in the performance I want to set the "fetchsize" of sql query. I know fetchsize can be preset in Java using Jdbc 2.0 API.Please let me know how to set this value in BPEL when using DBAdapter?
Thanks
ChandraI talked to the developer of the db adapter - and he told me this feature will be available in BPEL PM 10.1.3 (which is supposed to be production later this year, and a public beta soon). If this is an emergency I would recommend going throug Oracle support and have them file an enhancement for 10.1.2.0.2
hth clemens -
How to use property file - sql query define in property file
Hi All,
Anybody please tell me how to use property file.
I have placed sql query in propery file and I have to access this in my file.
well so far this is my code but don't know how to implement in the following ...
pstmt = con.prepareStatement("select * from registration where username=?");
instead of writting the query I want to use the property file.
so far I have developed the following code...
FileInputStream fis = new FileInputStream("querysql.property");
Properties dbProp = new Properties();
dbProp.load(fis);is the code correct... or is there another way to access property file
Please help.
please reply soon....
ThanksBefore answering, check if it's already been done here http://www.jguru.com/forums/view.jsp?EID=1304182
Maybe you are looking for
-
Last Page Header and Footer in XML Report
Hi I have one requirement , where except last page for an invoice, all other pages should have one header. Last page should have nothing header and in Body some information(Total details) should be displayed and in footer terms and conditions should
-
Hi- Is there process to change the fully qualified host name for 9iAS? The machine name of the mid-tier server will be changing. Is there a way to change this name? Thanks
-
I have shot an event on 24p settings on Panasonic AG DVX100A camera. I am doing this for the first time. I would like to know about the settings for digitizing it in FCP5 & Printing it on a Mini Dv tape as well as for burning a DVD. Thanks. MANDAR
-
Why app in ios6 crash frequently and lag .
why app in ios6 crash frequently and lag ios5.1 didnt' happen. Plz fix it OK To bad to saw it. And loss ours trust ios is best than others ... Maps is still bad to use. Search result is wrong. Plz fux ios6 OK To many bug.... Use 4S
-
WRT600N - Wireless Client Table BUG
The bug discussed in this thread http://forums.linksys.com/linksys/board/message?board.id=Wireless_Routers&thread.id=74677 still exists on the latest firmware.