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

Similar Messages

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

  • Populating JTable table from sql statement.

    Trying to teach myself a combanation of things. Since Oracle is my background java to oracle is only a natural. Now this code I'm trying to select some rows and then display those rows in a table. Simple concept as a teaching aid to me. I won't go into what I went through to get this far, just say there have been quite a few fall starts. Now this code works; however it returns ten rows (one for each tablespace) and displays row 1 ten times. Not quite what I had in mind.
    I have got a simple select statment in my code:
    select tablespace_name,initial_extent,next_extent,pct_increase, status
    from dba_tablespaces order by tablespace_name
    package TableTest;
    // java imports
    import java.util.Vector;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.awt.*;
    import javax.swing.*;
    // sql imports
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    public class TableTest extends JFrame
      Connection conn;  // database connection object
      Statement stmt;   // statement object
      ResultSet rslt;   // result set object
      //private vars
      private String userName         = "bubbalouie";
      private String password         = "helpmeimsinking";
      private String sid              = "rob";
      private String port             = "1521";
      private String server           = "w2sd001";
      private String connectString    = "jdbc:oracle:thin:@"+server+":"+port+":"+sid;
      private int numCols             = 5;
      private String sqlStmt          = null;
      private String status           = null;
      public TableTest()
        // Get content pane
        Container contentPane = getContentPane();
        // set layout manager
        contentPane.setLayout(new BorderLayout());
        // create some places to put dat
        Vector data    = new Vector();
        Vector columns = new Vector();
        Vector colHeads = new Vector();
        colHeads.addElement("tablespace name");  // this is ugly fix later
        colHeads.addElement("initial extent");
        colHeads.addElement("next extent");
        colHeads.addElement("pct increase");
        colHeads.addElement("status");
        // construct a simple sql statement
        sqlStmt = "select  tablespace_name, initial_extent, next_extent, pct_increase, status";
        sqlStmt = sqlStmt+" from dba_tablespaces order by tablespace_name";
        try
          // connect to database
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          Connection conn = DriverManager.getConnection(connectString, userName, password);
          // select data into object
          stmt = conn.createStatement();
          rslt = stmt.executeQuery(sqlStmt);
          while (rslt.next())
            for ( int i=0; i<numCols; i++ )
              columns.addElement(rslt.getObject(i+1));  // get the i+1 object
            }  // end for
            data.addElement(columns);
          }    // end while
          // create the table
          JTable table = new JTable(data,colHeads);
          // add table to scroll pane
          int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
          int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
          JScrollPane jsp = new JScrollPane(table,v,h);
          // Add scroll pane to content pane
          contentPane.add(jsp, BorderLayout.CENTER);
        } catch (SQLException ex)
          String msg = "SQL error: "+ex.toString();
        } catch (Exception ex)
          String msg = "Error: "+ex.toString();
      }                                     // end constructor
      public static void main(String[] args) {
          TableTest frame = new TableTest();
          frame.setSize(500, 400);
          frame.setTitle("TableTest");
          frame.setVisible(true);
    }  // TableTest end class

    if you are interested here is a generic table model for displaying ResultSets in a JTable. The resultset needs to support calling resultset meta data and the basic methods in there but then it should support anything you give it.
    import java.sql.*;
    import java.util.*;
    import javax.swing.table.*;
    public class ResultSetTableModel extends AbstractTableModel{
      Vector rows;          
      int[] types;          
      String[] names;     
      public ResultSetTableModel(ResultSet rs)throws SQLException{
        ResultSetMetaData rsmd = rs.getMetaData();          
        types = new int[rsmd.getColumnCount()];          
        names = new String[rsmd.getColumnCount()];          
        for(int n=0;i<types.length;n++){               
          types[n] = rsmd.getColumnType(n+1);
          names[n] = rsmd.getColumnName(n+1);     
        rows = new Vector();
        while(rs.next()){
          Vector aRow = new Vector();
          for(int j=0;j<types.length;j++){
               switch(types[j]){
              case Types.TINYINT:
                aRow.addElement(new Byte(rs.getByte(j+1)));
                break;
              case Types.SMALLINT:
                aRow.addElement(new Short(rs.getShort(j+1)));
                break;
                 case Types.INTEGER:
                   aRow.addElement(new Integer(rs.getInt(j+1)));
                   break;
                 case Types.BIGINT:
                   aRow.addElement(new Long(rs.getLong(j+1)));
                   break;
                 case Types.REAL:
                   aRow.addElement(new Float(rs.getFloat(j+1)));
                   break;
                 case Types.FLOAT:
                   aRow.addElement(new Double(rs.getDouble(j+1)));
                   break;
                 case Types.DOUBLE:
                   aRow.addElement(new Double(rs.getDouble(j+1)));
                   break; 
                 case Types.DECIMAL:
                   aRow.addElement(rs.getBigDecimal(j+1));
                   break;
                 case Types.NUMERIC:
                   aRow.addElement(new Long(rs.getLong(j+1)));
                   break;
                 case Types.BIT:
                   aRow.addElement(new Boolean(rs.getBoolean(j+1)));
                   break;
                 case Types.BINARY:
                   aRow.addElement(rs.getBytes(j+1));
                   break;
                 case Types.DATE:
                   aRow.addElement(rs.getDate(j+1));
                   break;
                 case Types.TIME:
                   aRow.addElement(rs.getTime(j+1));
                   break;
                 case Types.TIMESTAMP:
                   aRow.addElement(rs.getTimestamp(j+1));
                   break;           
                 default:
                   aRow.addElement(rs.getString(j+1));
          rows.addElement(aRow);           
      public Class getColumnClass(int column){
        switch(types[column]){
          case Types.BIT:
            return Boolean.class;
          case Types.DATE:
            return java.sql.Date.class;
          case Types.TIME:
            return java.sql.Time.class;
          case Types.TIMESTAMP:
            return java.sql.Timestamp.class;
          default:
            return Object.class;     
      public int getRowCount(){
        return rows.size();     
      public int getColumnCount(){
        return types.length;     
      public Object getValueAt(int row, int column){
        Vector aRow = (Vector) rows.elementAt(row);
        return aRow.elementAt(column);
      public String getColumnName(int column){
        return names[column];
    }

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

  • Odd results from SQL statement in JSP

    Hi.
    Getting very strange results from my SQL statement housed in my JSP.
    the last part of it is like so:
    "SELECT DISTINCT AID, ACTIVE, REQUESTOR_NAME, ..." +
    "REQUESTOR_EMAIL" +
    " FROM CHANGE_CONTROL_ADMIN a INNER JOIN CHANGE_CONTROL_USER b " +
    "ON a.CHANGE_CTRL_ID = b.CHANGE_CTRL_ID " +
      " WHERE UPPER(REQUESTOR_NAME) LIKE ? ";   I've set the following variables and statements:
    String reqName = request.getParameter("requestor_name");
    PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
    prepstmt.setString(1, "%" + reqName.trim().toUpperCase() + "%");
    ResultSet rslts = prepstmt.executeQuery();
    rslts.next();
    int aidn = rslts.getInt(1);          
    int actbox = rslts.getInt(2);     String reqname = rslts.getString(3).toUpperCase();
    String reqemails = rslts.getString(4);
    String bizct = rslts.getString(5);
    String dept = rslts.getString(6);
    String loc = rslts.getString(7);
    Date datereq = rslts.getDate(8);
    String busvp = rslts.getString(9);
    AND SO ONSo then I loop it, or try to with the following:
    <%
      try {
      while ((rslts).next()) { %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    rslts.close();
    selstmt.close();
    catch(Exception ex){
         ex.printStackTrace();
         log("Exception", ex);
    %>AND so on, setting 13 getXXX methods of the 16 cols in the SQL statement.
    Trouble is I'm getting wildly inconsistent results.
    For example, typing 'H' (w/o quotes) will spit out 20 duplicate records of a guy named Herman, with the rest of his corresponding info correct, just repeated for some reason.
    Typing in 'He' will bring back the record twice (2 rows of the complete result set being queried).
    However, typing in 'Her' returns nothing. I could type in 'ell' (last 3 letters of his name, Winchell) and it will again return two duplicate records, but typing in 'hell' would return nothing.
    Am I omitting something crucial from the while statement that's needed to accurately print out the results set without duplicating it and that will ensure returning it?
    There's also records in the DB that I know are there but aren't being returned. Different names (i.e. Jennifer, Jesse, Jeremy) won't be returned by typing in partial name strings like Je.
    Any insight would be largely appreciated.
    One sidenote: I can go to SQL Plus and accurately return a results set through the above query. Having said that, is it possible the JDBC driver has some kind of issue?
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20

    Am I omitting something crucial from the while
    statement that's needed to accurately print out the
    results set without duplicating it and that will
    ensure returning it?Yes.
    In this code, nothing ever changes the value of reqname or any of the other variables.
      while ((rslts).next()) { %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    } You code needs to be like this:while (rslts.next()) {
      reqname = rslts.getString(3).toUpperCase();
      reqemails = rslts.getString(4);
      bizct = rslts.getString(5);
      dept = rslts.getString(6);
      loc = rslts.getString(7);
      datereq = rslts.getDate(8);
      busvp = rslts.getString(9);
    %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    There's also records in the DB that I know are there
    but aren't being returned. Different names (i.e.
    Jennifer, Jesse, Jeremy) won't be returned by typing
    in partial name strings like Je.Well, you're half-right, your loop won't display all the rows in the result set, because you call rslts.next(); once immediately after executing the query. That advance the result set to the first row; when the loop is entered, it starts displaying at the 2nd row (or later if there are more next() calls in the code you omitted).

  • 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

  • Convert Archive Logs into SQL statements

    Hi Guys,
    I want to find out a way to convert ARCHIVE LOGS into sql staements. Is there any. Please help.
    Thanks

    look into logminer...
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/logminer.htm
    http://arjudba.blogspot.com/2008/08/how-to-use-oracle-logminer-to-analysis.html

  • Convert substring function from SQL Server to Oracle

    I am converting a large application written for SQL Server to Oracle and have encountered a difference in how the substring function is called between the two database systems.
    In SQL Server:
    select substring('xyz'1,2)
    In Oracle:
    select substr('xyz',1,2)
    Is there a way to establish a user-defined operator to map the substring call to a substr call so I don't have to change the application code?
    Is the user-defined function a way to do this?
    Which is better?

    If you want to be able to use the code that has substring in it, without modifying it, and have it do the same thing as substr, then try running the script below. It will create a user-defined function named substring that will cause substring to act like substr.
    CREATE OR REPLACE FUNCTION substring
    (p_string IN VARCHAR2,
    p_start IN VARCHAR2,
    p_end IN VARCHAR2 DEFAULT NULL)
    RETURN VARCHAR2
    IS
    v_string VARCHAR2 (100);
    BEGIN
    IF p_end IS NULL
    THEN
    SELECT SUBSTR (p_string, p_start)
    INTO v_string
    FROM DUAL;
    ELSE
    SELECT SUBSTR (p_string, p_start, p_end)
    INTO v_string
    FROM DUAL;
    END IF;
    RETURN v_string;
    END substring;
    null

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

  • (262119469) Q DBC-17 How is data mapped from SQL-type to Java-type?

    Q<DBC-17> Is there any documentaion for the data mapping between the "java type" and
    the "sql type"
    A<DBC-17> The data types are the standard JDBC mappings. Check the javadoc for the
    java.sql package.

    Hi,
              If you are seeing last 3 fields coming as empty.... then you need to check the seperator type which correctly seperats one fields from another during mapping to BW infoobject.
    Thanks
    Kishore Kusupati

  • SELECT returning different rows when issued from SQL Developer or Java apps

    Hi there. I'm facing a problem here: I'm trying to issue a SELECT from Java, which should return me 2 rows; but I'm getting just one. When I issue the SELECT directly through SQL Developer it gives me the expected result. I've pastebin the code at http://paste.uni.cc/11821, where I've described in details the problem.
    What could it be? Any help would be appreciated.
    Thanks in advance!

    Marco,
    I would code it a bit differently, but I don't think that would solve your problem.
    I suggest setting up the JDBC logging. I'm not promising it will help, but I guess it
    can't hurt. Here is a white paper about it:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/pdf/logging%20white%20paper.pdf
    You can also access that link from this Web page:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • Issue in retriving rows from sql statement

    hi all,
    actually i am trying to executed a query given below:
    select scodesc from t_coursecatalog where productid=13 and rownum=1;
    actually this particular column 'scodesc' contain very long insertion statement i.e.,
    <table border=0 cellpadding="1" cellspacing="1" bordercolordark="ffffff" border.......................
    but when i executed this query i can only able to see the half of the statement, i couldnt see the rest of the statement after 'border' in the reterived row
    it simply show
    select scodesc from t_coursecatalog where productid=13 and rownum=1;
    <table border=0 cellpadding="1" cellspacing="1" bordercolordark="ffffff" border..................
    so wat should i do nowat this situation..... is there any tuning is required here.
    if yes.how to tune? where to tune?
    plz help me in this topic
    its urgent plz

    Hallo,
    first of all: where do you run the statement ?
    In SQLPlus or in TOAD/Navigator/Developer ?....
    And what is the datatype and length for your column scodesc ?
    Regards
    Dmytro
    Message was edited by:
    Dmytro Dekhtyaryuk

  • Convert XML File from HTML file using java

    Hi All,
    I am trying to convert HTML file into XML file.
    But, Unfortunatelly didnt get the exact result.
    If anyone have a sample code please share with me.
    Any suggestions greatly appreciated.
    Thanks,
    Veera

    You can have a look at [http://sourceforge.net/projects/light-html2xml|http://sourceforge.net/projects/light-html2xml]

  • Generating CSV file with column names and data from the MySQL with JAVA

    Hi all,
    Give small example on ...
    How can I add column names and data to a CSV from from MySQL.
    like
    example
    sequence_no, time_date, col_name, col_name
    123, 27-apr-2004, data, data
    234, 27-apr-2004, data, data
    Pls give small exeample on this.
    Thanks & Regards
    Rama Krishna

    Hello Rama Krishna,
    Check this code:
    Example below exports data from MySQL Select query to CSV file.
    testtable structure
    CREATE TABLE testtable
    (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    text varchar(45) NOT NULL,
    price integer not null);
    Application takes path of output file as an argument.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class automateExport {
        public static void main(String[] args) {
            DBase db = new DBase();
            Connection conn = db.connect(
                    "jdbc:mysql://localhost:3306/test","root","caspian");
            if (args.length != 1) {
                System.out.println(
                        "Usage: java automateExport [outputfile path] ");
                return;
            db.exportData(conn,args[0]);
    class DBase {
        public DBase() {
        public Connection connect(String db_connect_str,
                String db_userid, String db_password) {
            Connection conn;
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                conn = DriverManager.getConnection(db_connect_str,
                        db_userid, db_password);
            } catch(Exception e) {
                e.printStackTrace();
                conn = null;
            return conn;
        public void exportData(Connection conn,String filename) {
            Statement stmt;
            String query;
            try {
                stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_UPDATABLE);
                //For comma separated file
                query = "SELECT id,text,price into OUTFILE  '"+filename+
                        "' FIELDS TERMINATED BY ',' FROM testtable t";
                stmt.executeQuery(query);
            } catch(Exception e) {
                e.printStackTrace();
                stmt = null;
    Greetings,
    Praveen Gudapati

  • Buffer size for SQL statement using JDBC calls

    I need to find out the buffer size for SQL statements in jave/JDBC because I need to insert or update a field that could be up to 4KB in size.

    I'm not sure that I follow the question; I'm not sure which buffer size you're referring to.
    If you have a field that can store up to 4k worth of data, you would create a VARCHAR2(4000) column in the Oracle database (assuming it is character data) or a BLOB column (if the data is binary). Either of those two fields can be populated from JDBC.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for

  • How to output any text to appointed place?

    I want to output some text from JTextField to one text field in browser.How to do it? Thanks for any suggestion.

  • Easiest way to identify/delete/prevent duplicate documents

    I don't suppose that the text column (e.g. CLOB) is something that I can use the usual trick to delete duplicates with, is it? I would think rather than compare the actual text column, I'd need to calculate a checksum or something for each document a

  • Referencing a source datagrid from within a drag and drop handler

    My application implements a drag and drop between two datagrids. I would like to keep track of how many times a particular row in the source datagrid has been dragged to the target. The drag and drop handler should increment a DataGridColumn in the s

  • Running v10.4 (intel) on a UFS formatted system volume

    Hello, My (recently deceased) iBook ran Mac OS X v10.3, and I used to be able to install it onto a UFS formatted system volume. This was very useful to me in my work. My new MacBook with v10.4 doesn't seem to allow this option during the install proc

  • Problem with Images JAVA ME

    Hi I am new to JAVA programming and I was wondering how to manipulate an image. I have created a list screen and I wanted to set a background image in it. is it possible? BTW I am developing a mobile device application using netbeans v5.0 with netbea