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 PM

Me 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]

Similar Messages

  • 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.
    Thanks

    http://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.

  • Convert a logic from SQL statement to java

    Hi.,
    I m using jdeveloper 11.1.1.5
    I had used one sql statement as gievn below
    (SELECT max(decode(LENGTH(fy_year),4, fy_year + 1,6,SUBSTR(fy_year, 1, 4)+1||SUBSTR(SUBSTR(fy_year, 1, 4) + 2, 3, 2)))YEAR from fin_years)I need to use this logic in java
    Could anyone pls help me

    "wilhelm,"
    I've seen some ridiculous questions in my life. This is one of them.
    There are just so many things wrong here. So, so many.
    SELECT statements get data from databases; they are not "logic."
    Do you really expect us to parse your SQL and try to guess what it is supposed to do?
    Do you really believe that when converting a Forms app to Java that you "convert" SQL statements to Java?
    Do you really believe that going through your forms app and "converting" it to ADF is a sensible approach?
    John

  • SQLException: Closed Connection, SQL state [null]; error code [17002]

    Hello All,
    I am supporting a Java 5 project on Tomcat. We've used Spring and Stored Procedure in the project.
    Recently we deployed our application in a GoLive environment and have started seeing Timeout errors in log files. After around two days we also have to restart Tomcat as users are no more able to login to access the application.
    Same application runs fine without any timeout issues on another environment.
    The only difference between two environments is that the Go-Live env has a firewall between Tomcat and Database and the other environment hosts both Tomcat and Database on same machine (i.e. no firewall).
    For GoLive env the only port open on firewall for JDBC connection is 1521 and is used in the connection string url for obtaining the connections.
    When there is a Timeout error, the N/w admin guy observed that the JDBC connection was not attempted on 1521 port, but on some random port which is not open on firewall, due to which the Database server logs also do not show entry for this connection attempt as it gets blocked by the firewall.
    I am not sure why a randam port should be used to connect when a specific port is mentioned in the connection url? Also what can be making this port switching?
    Application uses Apache DBCP with Spring to obtain connections.
    Has anyone experienced similar errors?
    Any suggestions/help on this issue is greatly appreciated!
    Many Thanks,
    CD
    ===============================
    Error Log Extract:
    Error while extracting database product name - falling back to empty error codes
    org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: Closed Connection
    java.sql.SQLException: Closed Connection
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
    at oracle.jdbc.driver.PhysicalConnection.getMetaData(PhysicalConnection.java:1605)
    at org.apache.commons.dbcp.DelegatingConnection.getMetaData(DelegatingConnection.java:247)
    at org.apache.commons.dbcp.DelegatingConnection.getMetaData(DelegatingConnection.java:247)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.getMetaData(PoolingDataSource.java:231)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:172)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:207)
    at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:187)
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:126)
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:92)
    at org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:96)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:294)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:348)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:352)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:356)
    at com.o2.morse.dao.impl.sql.UserDaoImpl.batchLoad(UserDaoImpl.java:371)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
    at $Proxy3.batchLoad(Unknown Source)
    at com.o2.morse.domain.User.doHousekeeping(User.java:667)
    at com.o2.morse.domain.User$$FastClassByCGLIB$$372ff70b.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:705)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
    at com.o2.morse.domain.User$$EnhancerByCGLIB$$d5ac966a.doHousekeeping(<generated>)
    at com.o2.morse.scheduler.EndOfDay.run(EndOfDay.java:63)
    at com.o2.morse.scheduler.EndOfDay$$FastClassByCGLIB$$3b2d4927.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:705)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
    at com.o2.morse.scheduler.EndOfDay$$EnhancerByCGLIB$$488a9f86.run(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:165)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:90)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    Could not close JDBC Connection
    java.sql.SQLException: Already closed.
    at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:77)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:180)
    at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:286)
    at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:247)
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion(DataSourceTransactionManager.java:297)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:615)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:560)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.doCloseTransactionAfterThrowing(TransactionAspectSupport.java:284)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:100)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
    at $Proxy3.batchLoad(Unknown Source)
    at com.o2.morse.domain.User.doHousekeeping(User.java:667)
    at com.o2.morse.domain.User$$FastClassByCGLIB$$372ff70b.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:705)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
    at com.o2.morse.domain.User$$EnhancerByCGLIB$$d5ac966a.doHousekeeping(<generated>)
    at com.o2.morse.scheduler.EndOfDay.run(EndOfDay.java:63)
    at com.o2.morse.scheduler.EndOfDay$$FastClassByCGLIB$$3b2d4927.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:705)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
    at com.o2.morse.scheduler.EndOfDay$$EnhancerByCGLIB$$488a9f86.run(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:165)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:90)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    Application exception overridden by rollback exception
    org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL [SELECT ID_USER_DETAILS, USERNAME, CREATED_ON, LAST_LOGIN FROM USER_DETAILS  WHERE STATUS = 157 AND SUPERUSER <> 'Y']; SQL state [null]; error code [17002] ; Io exception: Connection timed out; nested exception is java.sql.SQLException: Io exception: Connection timed out
    java.sql.SQLException: Io exception: Connection timed out
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
    at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:820)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1049)
    at oracle.jdbc.driver.T4CStatement.executeMaybeDescribe(T4CStatement.java:845)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1154)
    at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1313)
    at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:205)
    at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:205)
    at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:333)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:282)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:348)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:352)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:356)
    at com.o2.morse.dao.impl.sql.UserDaoImpl.batchLoad(UserDaoImpl.java:371)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
    at $Proxy3.batchLoad(Unknown Source)
    at com.o2.morse.domain.User.doHousekeeping(User.java:667)
    at com.o2.morse.domain.User$$FastClassByCGLIB$$372ff70b.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:705)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
    at com.o2.morse.domain.User$$EnhancerByCGLIB$$d5ac966a.doHousekeeping(<generated>)
    at com.o2.morse.scheduler.EndOfDay.run(EndOfDay.java:63)
    at com.o2.morse.scheduler.EndOfDay$$FastClassByCGLIB$$3b2d4927.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:705)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
    at com.o2.morse.scheduler.EndOfDay$$EnhancerByCGLIB$$488a9f86.run(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:165)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:90)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    Batch Job Failed: org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is java.sql.SQLException: Closed Connection

    I am using latest Jrockit 16)5, ojdbc6_g.jar,spring.jar Weblogic 10.3 and Oracle 10G 10.2.4 .. whatever but always get "Closed Connection"
    java.lang.Throwable: Closed Connection
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
    at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:750)
    at oracle.jdbc.OracleConnectionWrapper.createStatement(OracleConnectionWrapper.java:183)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7053)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)

  • Pretty printing SQL statements in Java

    Hello,
    Environment: Oracle 10g (no prepared statements) and WebLogic 10 using WL's connection pooling.
    We have dynamically generated SQL in our Java code and currently print the SQL to our (log4j) logger as one long Java String. Does Oracle offer a method call to better format the SQL prior to calling the logger to log the SQL?
    Thanks,
    Jim

    Hi Jim,
    Just an idea. Oracle SQLDeveloper has a formatting utillity. Since the IDE is written in Java, there just might be a jar/class that can be used elsewhere.
    As said, just an idea. Maybe you can download it and try to investigate yourself.
    Best regards
    Peter

  • Pleasse How To  Compute Spaces in Statement (by JAVA code)

    hi
    Please can you help me ;
    How To Compute Spaces in Statement (by JAVA code) .
    Best Regards;

    Hi,
    can you be more specific? What statement? If it is a string you can use a String buffer and add spaces to wherever you want within a string.
    Frank

  • 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........

  • Executing a DDL statement from java code

    Hi all,
    this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
    I am trying to create a table in same schema in same db by using 'Copy' command.
    Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
            public String cmb_action() {
            // Add event code here...
            try {
                //getting source db connection
                InitialContext initialContext = new InitialContext();
                DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
                Connection sourceconn = ds.getConnection();
                sourceconn.setAutoCommit(false);
                String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"                       
                Statement stat = sourceconn.createStatement();
                stat.executeUpdate(sql);
                sourceconn.commit();
                System.out.println("done");
              catch (Exception ne) {
                // TODO: Add catch code
                ne.printStackTrace();
            return null;
        }

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • Multiple sql statements from java

    I am executing sql statements in MaxDB 7.6.04.12 from java using jdbc.
    I want to execute multiple statements at a time, but it seems that however I separate the statements, I get
    com.sap.dbtech.jdbc.exceptions.DatabaseException: [-3014] (at 433): Invalid end of SQL statement
    I have tried separating the statements with just a semi-colon, with a semi-colon and new line, with newline-//-newline (as works with SQL Studio), but whatever I try I get this error or some other.
    Is it possible to do this? and if so how?
    Thanks
    Chris

    Hi Lars,
    Here are the relevant bits of code.
    However I'm not sure how helpful that will be - I'm using the SpringFramework for my jdbc calls, as it saves a lot of time and effort, and my calls are to Spring methods, which are wrappers round the base jdbc calls.
    I'll post it anyway, just in case you're familiar with Spring. I haven't looked at the Spring code, but my understanding is it pretty much just passes the sql to standard jdbc calls.
    I guess my next step would be to trace through the Spring code as it executes and see if anything becomes apparent. However I'm under some time pressure and was hoping to avoid that.
    My other alternative is to create non-temporary tables, and drop them explicitly when I've finished with them.
        public Set<String> getPriceUpdatedProducts() {
            final Set<String> prods = new TreeSet<String>();
            String sql;
            int updates;
            // need single connection template so subsequent statements can access temp tables:
            JdbcTemplate jtSingle = getSingleConTemplate(jdbcTemplate);
            // inDCs is a list of dist channels for an sql 'in' statement:
            String inDCs = "";
            for (String siteId: siteConfig.getAllSiteIds()) {
                if (!"".equals(inDCs)) inDCs += ",";
                inDCs += "'" + siteConfig.getSiteIdProperty(siteId, "distChanId") + "'";
            // Clear all the changed flags from the last run:
            updates = jtSingle.update("update zchangedartdc set changed = '' ");
            // Get the current data into a temp table:
            sql = "create table temp.pricechanges as " +
                  "select A304.matnr, A304.vtweg, konp.kbetr price " +
                  "  from A304 join konp " +
                  "    on A304.knumh = konp.knumh " +
                  "   and A304.mandt = konp.mandt " +
                  "   and A304.vkorg = '" + salesOrg + "' " +
                  "   and A304.vtweg in (" + inDCs + ")" +
                  "   and A304.kschl = '" + rrpCondType + "' " +
                  "   and A304.mandt = '" + sapClient + "' " +
                  "   and konp.kschl = '" + listCondType + "' " +
                  "   and char(date, internal) >= chr(A304.datab) " +
                  "   and char(date, internal) <= chr(A304.datbi) " +
                  "   and A304.kappl = 'V' ";
            jtSingle.execute(sql);
            // Get the changes into a second temp table:
            sql = "create table temp.changedarts as " +
                  "select temp.pricechanges.* " +
                  "  from temp.pricechanges, zchangedartdc " +
                  " where zchangedartdc.matnr = temp.pricechanges.matnr " +
                  "   and zchangedartdc.vtweg = temp.pricechanges.vtweg " +
                  "   and zchangedartdc.price != temp.pricechanges.price ";
            jtSingle.execute(sql);
            // save the changes, and flag them:
            sql = "update zchangedartdc " +
                  "   set (price, changed) = (select price, 'X'  " +
                  "                             from temp.changedarts " +
                  "                            where zchangedartdc.matnr = temp.changedarts.matnr " +
                  "                              and zchangedartdc.vtweg = temp.changedarts.vtweg) " +
                  " where matnr||vtweg in (select matnr||vtweg from temp.changedarts) ";
            updates = jtSingle.update(sql);
            // add the new items that weren't there last time, and flag them:
            sql = "insert into zchangedartdc " +
                  "select '" + sapClient + "', matnr, vtweg, 'X', price " +
                  "  from temp.pricechanges " +
                  " where matnr||vtweg not in (select matnr||vtweg from zchangedartdc) ";
            updates = jtSingle.update(sql);
            // now we've got all the changes flagged, we can get the list of changed products:
            jtSingle.query("select distinct matnr from zchangedartdc " +
                           " where changed = 'X' ",
                           new RowCallbackHandler() {
                               public void processRow(ResultSet rs) throws SQLException {
                                   prods.add(rs.getString("matnr"));
            // release the connection:
            destroySingleConnection(jtSingle);
            return prods;
         * Return a JdbcTemplate which will always use the same connection. Parameter jt is just
         * a convenient way to get a DataSource from which to get a Connection.
         * When the calling prodedure has finished, it MUST call
         * destroySingleConnection(jt)
         * @param jt
         * @return
        private JdbcTemplate getSingleConTemplate(JdbcTemplate jt) {
            Connection con;
            try {
                con = jt.getDataSource().getConnection();
                con.setAutoCommit(true);
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to get Connection for SingleConnectionDataSource", e);
            SingleConnectionDataSource singleDs = new SingleConnectionDataSource(con, true);
            return new JdbcTemplate(singleDs);
        private void destroySingleConnection(JdbcTemplate singleConJt) {
            try{
                ((SingleConnectionDataSource)singleConJt.getDataSource()).destroy();
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to destroy SingleConnectionDataSource", e);

  • 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.

  • Help with sql statements and Java

    Hi,
    How can I create a string kind of like this
    Select * From Students Where Name Like "Bob Burns";
    As the sql statement might indicate I am using MS Access. I seem to be having problems with the double quotes required by the Like operator in MS Access, Java views that as a beginning of a string as oppposed to an actual string value.

    Like this:
        Connection connection = null;
        PreparedStatement stmt = null;
        ResultSet res = null;
        try  {
            connection = ...get from connection pool...;
            String sql = "select ... from ... where name like ?";
            stmt = connection.prepareStatement(sql);
            stmt.setObject(1, "%Bob%", java.sql.Types.VARCHAR);
            res = stmt.executeQuery();
            while (res.next()) { ...the usual...; }
        } finally {
            ...close res, stmt & return connection to pool...
        }You can try stmt.setString() instead of setObject() but rumor has it that some mssql drivers have a bug that makes setString() not work with "like", but oddly enough setObject() works.

  • Converting SQL statements from MS server 2000 to Oracle 10g

    We are moving over from MS server 2000 to Oracle 10g as our database for Peoplesoft system.
    There are several embedded SQL statements that I need to investigate to see what needs converting.
    So far I can see a need to convert the following:
    Dates.     GetDate() to ?
    Outer joins. *= to LEFT OUTER JOIN
    Has anyone else done a similar exercise and what other functions do I need to convert?
    Thanks.

    Hello
    A quick google search (http://www.google.co.uk/search?hl=en&q=ms+sql+server+oracle+differences&spell=1)
    came up with this:
    http://dba-oracle.com/oracle_news/2005_12_16_sql_syntax_differences.htm
    There's a quite a few more sites listed.
    HTH
    David

  • How can i add more statements in java code dynamically...

    I have a (business works) BW process in TIBCO which has many activities including �java code�. In java code activity I have some if statements like
    if (Country.equals("USA�))
    Country code = 1
    else if(Country.equals("GERMANY�))
    Country code = 49
    the above information is coming from database. now my project is deployed and running. In future, if they add more countries in database how I can include them dynamically without changing my BW process java code activity and redeploying again. Is there any solution?
    Please advice.

    You won't reconfigure the Java application without redeploying. This is one of the reasons that including data in the code is bad.
    If you created a file which contained data like this:
    Canada <tab> 1
    USA <tab> 12
    Germany <tab> 6
    Then your program could read the file into a map. The map could be used to lookup the country code based on the name.
    In the future, you could change the file to:
    Canada <tab> 1
    USA <tab> 12
    Germany <tab> 6
    France <tab> 17
    China <tab> 2
    And the program wouldn't need to be changed. You would just need to send out the new country file.

  • SQL State S0001 error code 18456 for named sql server : jdbc errors

    When I try to connect to named instance of SQL Server 2005,the error I get it
    The database user has data reader and writer rights.
    I have used sqljdbc4.jar
    url is jdbc:sqlserver://SERVER_NAME:1433;databaseName=DATABSE_NAME;user=USERNAME;password=USER_PASSWORD
    I also tried using the jtds driver and I get State 28000 error

    You might want to make sure that the instance is specified.
    For example, when connecting to SQL Server 2008 using DBVisualizer (free) with SingleSignOn authentication, you need to use the jTDS driver AND you have to specify the instance on the server in order to connect.
    Instance-less connection requests are rejected with the same error message as wrong password:
    java.sql.SQLException Error Code: 18456

  • Writting a SQL statement with Java

    Hello,
    I would like to perform an interrogation of my database but I have some trouble... here is the code I use (with MySQL) :
    String requete = "SELECT * FROM produit WHERE NomChimique ='butanol'";
    rs = stmt.executeQuery (requete); With this requete I find the record I have in my db. But with the following string the record is not found String requete = "SELECT * FROM produit WHERE NomChimique ='(+)-2-BUTANOL'";What I have not understand ?
    Thank you for your help,
    Jean-Marie

    I perform a first SELECT statement without WHERE,
    then I copy and past the value of the two exemples I
    give, the first succed, the second not...
    I am a little bit disappointed
    Jean-Marieyou should only be disappointed in yourself. this is NOT a Java problem. this is a Jean-Marie problem.
    one of the following is true...
    - the record does not exist
    - you are fouling up the result set handling and not noticing the record
    - something is going wrong with your query parsing
    So...
    make sure it exists.
    make sure you are connecting to the database you think you are.
    check over your result set code
    use preparedstatements
    ff all those fail then post your code (USING THE CODE TAGS) and someone will be delighted to help.

Maybe you are looking for

  • Error in ARE 1 Output- Excise Exempt

    Hi Experts, after carrying out the transaction code J1IA101 for the excise exempt invoice. We are not getting any value in the value column. The excise duty percentage is also not coming. There are no remarks printed although the same is maintained i

  • Struts2 - Escape form values while submitting

    Hi, I am using struts2 and annotations for validations. In my form, when i put following text in any textbox and say validation gets failed then same form display again but the textbox (Where I entered following text) shows wrongly, i mean text box s

  • Bottom portion of address doesn't print with labels...??

    g3 tiger printing labels--no problems g4 ibook--haven't tried macbook c2d--when choosing labels can't change the default size of print from 12 to 10 and when previewing it shows a different avery format(2 columns not 3). i checked the label, and layo

  • How do i update the iphone3gs?

    I wanted to download an app in the app store, but my iphone3gs said that i have to update... so i went to setting general BUT there is no software update button please tell me how to update my phone

  • Trying to set up a version cue server

    I'm new to Version Cue, never used it. I'm trying to use Version Cue through Bridge. In the Content window I see Browse Servers and Recent Projects, but not Start My Server. In the Bridge Preferences Adobe Version Cue and VersionCueSDKLoader are chec