Finding max value in column using java..

Hello there!!
I have a problem that i tried finding in google but did not get what i wanted.. that's why i hope you guys could help me out.
How do i find the maximum value in a column using resultset..
for example..
Connection con = DriverManager.getConnection("jdbc:mysql:///eproc","root", "");//eproc is dbase name in MySQL
Statement stmt=con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT MAX(id) FROM cat_work_sor_category");now, how do i use resultset to make sure i get the max value and assign to integer variable...
Please do help me out.
Thankyou.

Connection con =
DriverManager.getConnection("jdbc:mysql:///eproc","roo
t", "");//eproc is dbase name in MySQL
Statement stmt=con.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT MAX(id) FROM
cat_work_sor_category");
Integer MaxValue = new Integer(-1);
if(rs.next()){
MaxValue = rs.getInt(1);
int MAX_VALUE = MaxValue.intValue();

Similar Messages

  • How to Pass Click Value to DB using Java

    How to Pass Click Value to DB using Java and display tat
    clicked value row data in flex
    i have created connection with Sql Server using java and drew
    pie chart from values fetched from XML file created by Java
    wat i need is when i click pie chart region (widget) i should
    display a alert by giving value of particular widget name and Value
    from Database and display in Flex Alert

    Use AddResource to add Javascript in your BackingBean Code and pass the value to your javascript code.
    JSCookMenu and other dynamic adding of javascript to a JSF-JSP page is done using AddResource....

  • Search for a Multilingual value in MDM using JAVA API

    Good day,
    Could you kindly assist.
    I am trying to search for a field in MDM, from Portal using JAVA API. I do retrieve the value in English, but the problem is when I am trying to retrieve it in other languages. Please see sample code:
         private Search getSearch(MDMConnection mdmconnection,String value, TableId tableid){
              Search search =null;
              FieldSearchDimension fielddimension=null;
              TextSearchConstraint textcontrain=null;
              RepositorySchema reposchema =mdmconnection.reposchema;          
                                               if(value!=null)
                   search= new Search(tableid);
                   fielddimension=new FieldSearchDimension(reposchema.getFieldId("ATTR_VAL_ABBR","TEXT_VALUE"));
                   textcontrain=new TextSearchConstraint(value,TextSearchConstraint.EQUALS);
                   search.addSearchItem(fielddimension,textcontrain);
                   search.setComparisonOperator(Search.AND_OPERATOR);
              return search;
    Thank you in advance.
    Regards,
    Simni

    Hi ,
    Mdm- Multilingual value in MDM using JAVA API:
    you can check the first point as its reagrdign youisue related pdf and soloutions for your question.
    1.  http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0e8aedc-cdfe-2c10-6d90-bea2994455c5?QuickLink=index&overridelayout=true
    2.  http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0e8aedc-cdfe-2c10-6d90-bea2994455c5?QuickLink=index&overridelayout=true
    Hope this information helps you in solving the  issue!!
    Thanks&Regards
    AswinChandraGirmaji

  • How to find max(time) from table using group by

    how to find max(time) from table using group by
    select var max(time)
              from table
              into (var1, time1)
               where .....
                 group by var.
    it is fetching record which is top in table.
    if u can help?
    regards.

    No this will fetch the maximum time from teh table.
    select var max(time)
    from table xxxx
    into (var1, time1)
    where .....
    group by var.
    Refer this code
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.

  • Query help needed in finding max value between two columns

    I have a table as follows:
    -- INSERTING into TESTTABLE
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('A','4.5','AA',0.3,'AB',5.5);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('B','1','BB',2.5,'BC',6.9);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('C','2.6','CC',3.3,'CD',1.4);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('D','1.8','DD',2.9,'DE',1.2);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('E','6.8','EE',4.8,'EF',9.6);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('F','2.0','FF',6.34,'FG',3.9);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('G','1.7','GG',3.6,'GH',5.8);
    I want to get results as follows:
    COLA COL2 MaxCol MaxColVal
    A 4.5 AB 5.5
    B 1 BC 6.9
    C 2.6 CC 3.3
    D 1.8 DD 2.9
    E 6.8 EF 9.6
    F 2.0 FF 6.34
    G 1.7 GH  5.8I want to get the max value of either of the columns COLD or COLF.. Whichever column has got max value, then the corresponding value of COLC and COLE should be returned..
    For eg., in first row, COLF has higher value than COLD.. ie., COLF = 5.5 > COLD = 0.3, so for row1, i want the result as MaxCol is AB and MaxColvalue is 5.5..
    Similarly for third row, COLD =3.3 > COLF=1.4, so for 3rd row, i want the result as MaxCol is CC and MaxColvalue is 3.3
    How is it possible to do this in a qery? Any help.. please..

    SQL> select cola
      2       , col2
      3       , case greatest(cold,colf)
      4         when cold then colc
      5         else cole
      6         end maxcol
      7       , greatest(cold,colf) maxcolval
      8    from testtable
      9  /
    C COL MA  MAXCOLVAL
    A 4.5 AB        5,5
    B 1   BC        6,9
    C 2.6 CC        3,3
    D 1.8 DD        2,9
    E 6.8 EF        9,6
    F 2.0 FF       6,34
    G 1.7 GH        5,8
    7 rijen zijn geselecteerd.Regards,
    Rob.

  • Retriving all records in the value mapping cache using java

    Hi,
    Is there a way to retrieve all records assuming I properly maintain some values in the value mapping using java? I know and I tried retrieving already using XIVMService.executeMapping but it seems that I can retrieve only 1 value at a time.
    For instance, in the value mapping cache I have the following:
    Agency         Schema         Value                Context
    SENDER       KEY              0001&ABC        http://xyz.com/ECC/ZTABLE
    SENDER       KEY              0003&           http://xyz.com/ECC/ZTABLE
    SENDER       KEY              0004&DEF        http://xyz.com/ECC/ZTABLE
    RECEIVER     RESULT           Hello           http://xyz.com/ECC/ZTABLE
    RECEIVER     RESULT           World           http://xyz.com/ECC/ZTABLE
    RECEIVER     RESULT           Hi              http://xyz.com/ECC/ZTABLE
    Is it possible to retrieve all values under the column Values assuming I know the value Agency, Schema and Context columns using a java program? If yes, can you point where I can find such an example code or if you are pointing to http://help.sap.com/javadocs/NW04S/current/pi/index.html please provide a sample code on how this can be done.
    Many thanks.

    Hi,
    Have you seen this weblogs by Prasad recently:
    /people/prasad.illapani/blog/2007/03/08/performance-tuning-checks-in-sap-exchange-infrastructure
    /people/prasad.illapani/blog/2007/04/20/performance-tuning-checks-in-sap-exchange-infrastructurexi-part-ii
    Also are you doing multiple lookups or a single lookup? If you are using multiple lookup for multiple fields which has the same logic then try to use global variables.
    ---Satish

  • Value cannot refresh using Java bean

    When I use java bean to get a value. It suppose to refresh and show new value but it doesn't. So any code can help to resolve this issue.
    here is my code
    (Testing.jsp)
    <html>
    <head>
    <title>Page 3</title>
    <link rel=stylesheet type="text/css" href="auction.css">
    </head>
    <table class="mainBox" width="200">
    <tr><td class="boxTitle" >
    Testing number 3
    </td></tr>
    <tr><td>
    <span class="headline">
         <jsp:useBean id="testing2" class="com.jsp.newsys.testing.Testing2" scope="request">
         <jsp:setProperty name="testing2" property="user" value="Hello World"/>
    <jsp:getProperty name="testing2" property="user2"/>
         </jsp:useBean>
    </span>     
    </td></tr>
    </table>
    </html>
    The bean file which is Testing2.java
    package com.jsp.newsys.testing;
    import java.beans.*;
    import java.util.*;
    public class Testing2 extends Object implements java.io.Serializable {
         private String user;
         private String test;
    public Testing2() {
    public void setUser(String user)
              test="";
              if (user.equals("Hello World"))
                   test="Hi dqwqwd";
         public String getUser2()
         return this.test;
    I need to restart my tomcat everytime then only the value will refresh. Please help.
    Message was edited by:
    wesleygch
    Message was edited by:
    wesleygch
    Message was edited by:
    wesleygch

    Your bean maybe have misspelling error
    look at test and test2 on the jsp file. But I couldn't find any bean property test2 in your bean. Maybe you should try
    ${testing2.test} instead of ${testing2.test2}
    I am a new bie also....:-)

  • How to find max value from a list of numbers stored in a varray?

    hi,
    Can any body help me to get the max value from a list of numbers stored in a varray?
    thanks in advance....
    regards
    LaxmiNarsimha

    Yes. Could you post what you have tried before we start helping you in this?

  • How to find Number of working threads using java executor framework

    I'm creating a java thread pool using java 1.5 executor framework.
    private ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
    public <T> Future<T> submit(Callable<T> task) {
              return executorService.submit(task);
    }Now I want to get the number of working thread at runtime. Is there any java api available to do this using java 1.5 executor framework?
    Thanks,
    Arpan

    If the ExecutorService you are working on is a ThreadPoolExecutor then you can use ThreadPoolExecutor#getActiveCount() to get the count of threads actually running tasks. There is no such method on the ExecutorService interface though.

  • How can i find the max of a column using CMP

    I urgently need a solution to How one can find the maximum of a field which is of integer/numeric type??
    I am doing it in CMP + weblogic.
    Suppose the table is STUDENTMARKS which consists of a field
    TotalMarks of Integer type..
    and i need to find the student with maximum marks..
    Should i be using EJB QL.. If so pls tell how...

    U can use aggregate function max in ejb ql

  • Get Field Values from Table using Java api

    I am using the example java code "RetrieveLimitedRecords" that can be found at :
    https://help.sap.com/javadocs/MDM71/current/API/index.html
    The code give the expected result and retrieves the record count for the main table
    Now I want to get the values of the fields for one record
    I added the lines:
    Record[] records = recordResultSet.getRecords() ;
    FieldId[] fields = records[0].getFields();
    System.out.println ("Field Length = "+fields.length);
    and the output is::
    Field Length = 0
    How can I get the fields of the record and read their values?
    Thanks
    Nicolas

    Assuming you want every field, the equivalent of "SELECT *" in SQL, you can use the RepositorySchema object to get a TableSchema, and with that get all FieldIds for the table.
    If your RepositorySchema variable is rs it would be something along the lines of:
    TableSchema mainTableSchema = rs.getTableSchema(mainTableId);
    ResultDefinition rd = new ResultDefinition(mainTableId);
    rd.setSelectFields(mainTableSchema.getFieldIds());
    Hope this helps,
    Greg

  • Generating value of column using sequence in Toplink

    Hi
    I have a toplink pojo table, say SamplePojo. I need to automatically generate a value for the primary key field, say id. Is it possible to insert only the name field into the table and let toplink generate a value for id field using sequence?
    I try the following code from my client class
    Project project = XMLProjectReader.read("META-INF/tlMap.xml", Thread.currentThread().getContextClassLoader());
    DatabaseSession session = project.createDatabaseSession();
    session.shouldLogMessages();
    session.login();
    String query = "insert into SAMPLE_POJO(NAME) values('SAMPLE NAME')";               
    session.executeSQL(query);
    session.logout();If i execute the above code i get a error like "Internal Exception: java.sql.SQLException: ORA-01400: cannot insert NULL into ("MYSCHEMA"."SAMPLE_POJO"."ID")"
    This is how my SamplePojo class looks like
    @Entity
    public class SamplePojo iimplements Serializablel {
        @Id
        @GeneratedValue(generator = "sampleSequence")
        @SequenceGenerator(name = "sampleSequence", sequenceName = "SAMP_SEQ", allocationSize = 1)
        private BigDecimal id;
        private String name;
        public SamplePojo(BigDecimal id, String name) {
            this.name = name;
            this.id = id;
    //getters and setters for class variables
    }

    Are you trying to use JPA, or the native TopLink API?
    Your annotations are JPA, but your code is the native API, using the XMLProjectReader.read("META-INF/tlMap.xml"), either use one or the other.
    With JPA, you will just have a persistence.xml, and optionally an orm.xml (you will not use the Mapping Workbench).
    To insert an object you just create an instance of the class and call persist(), no SQL.
    i.e.
    EntityManager em = factory.createEntityManager();
    em.getTransaction().begin();
    SamplePojo pojo = new SamplePojo();
    pojo.setName("SAMPLE NAME");
    em.persist(pojo);
    em.getTransaction().commit();
    James : http://www.eclipselink.org

  • How to find file type (Binary/Ascii) using Java IO

    Hi
    I want to find whether the file is binary file or not.
    Can any one please help.
    Thanks,
    Joy

    Encephalopathic wrote:
    I'm no IO expert, but aren't all files binary?Yes.
    I think what the OP is after is how to tell if a file contains only characters (e.g. ASCII characters). This can be done by reading the file and checking if every byte is a valid ASCII character more or less. An example would be limiting byte values to 9 (tab), 10 (LF), 12 (FF), 13 (CR), and 32-127.

  • How to find max value in single row

    i would like to know that,
    how can i display maximum value among several values in a single row of table
    example : i have to get value 5
    among 1 2 3 4 5 values of same row.

    Take a look at GREATEST function.
    C.
    Link to documentation added
    Message was edited by:
    cd

  • How to find max based on 2 columns.

    Hi I have a table where I have two numeric fields (date and time) )(thouse field are not date time format but numeric)
    Column A represents date and column B represent time.
    How would I find max value of column A and with results for A find Max for B.
    example
    A - - - - - - - - - -B
    101010 - - - - - 202020
    101011 - - - - - 202021
    101012 - - - - - 202021
    101010 - - - - - 202022
    101012 - - - - - 202020
    What I looking for is
    A - - - - - - - - - - B
    101012 - - - - - 202021
    Thanks

    You can try one of the following...
    sql> select * from temp;
             A          B
        101010     202020
        101011     202021
        101012     202021
        101010     202022
        101012     202020
      1  select a,b from (
      2     select a,
      3            b,
      4            rank () over (order by a desc, b desc) rnk
      5       from temp
      6* ) where rnk = 1
    sql> /
             A          B
        101012     202021
      1  select a,b from (
      2    select a,b from temp
      3       order by a desc, b desc
      4* ) where rownum = 1
    sql> /
             A          B
        101012     202021Please try to provide create table statements and insert data scripts instead of "select * from table".
    It helps creating your case easier.

Maybe you are looking for

  • Can you set up an automatic page update based on time?

    I was curious if, in dreamweaver, you can set up a page to automatically update at a certain time. For instance, I want the home page to replace 2 buttons at 12:30pm on November 3. Is this possible? Or do I have to upload a page manually at that time

  • Battery with red line after dropping 8800

    Yesterday I dropped my 8800 on a laminate floor.  Screen went all white.  I took out battery for a few secs, then had blank screen with green led flashing. Now it just has a battery icon with a red line through it.  Have I killed it? Be grateful for

  • Hyper-v cannot boot Gen2 guest from Windows 2012 R2 or Windows 8.1 x64 ISO - file format not supported, Gen1 works fine

    I am new to Gen2 Hyper-V and so far I simply can't use it, because I am unable to install any (supported) guest OS from an ISO ... So far I tried that on: 1. my HP Z230/i4770 workstation (Secure Boot disabled) host running Windows 8.1 Pro x64 (with H

  • The tricky logminer in 8.0.5

    I'd the need of mine some old information for this weird ethic committee. and after a while, i found myself writing a small guide that will help the poor souls chained to old oracle server releases. I hope it helps. As many of you know there was not

  • JFServer.exe fault in Windows 2008 server with Central V 5.7

    I have an installation of Central 5.7 running 6 instances on Windows 2008 server 64 bit and have noticed that the six instances don't always come up when the machine is rebooted.  Here is the error that it logs in the Central Log.  "Open of table 'C: