Generating next number from the SQL database using java

Hi friends, I have a problem and need your help. I am working on a project about submitting claims form through the adobe PDF file and SQL database. I have problem working on a web service (written in java) that will generate the next Invoice Number from the SQL Database table. The field type for the column is text(var char). *Example: I first need to get into the table and search for the last Invoice number in the table and if the last invoice number in the table from the database is 3, i would want to generate the next number which is 4 and filled it up in the PDF file through web service that i am implementing. Can you all provide me some guidelines on how to implement this method in my web service?
Thanks a lot. I need it by today. Hope someone can reply this as soon as possible.
Lim89
Edited by: LIM89 on Apr 2, 2008 7:10 PM

far simpler to use a sequence generator, which most databases support.
Suggested method to get the max value in the column is NOT secure, unless you lock the entire table for update before you do so, which is a severe performance penalty.

Similar Messages

  • How to create sql database using java frame or appelet?

    hi ! i am working on database project i want to create a database using java frame or applet where it asks user to select the location for database to be created , after user have specified the path then the programs creates the database, again i want that database to be read and write by another frame or applet but as user select the path how do i make the connectivity. i just have basic knowledge on java. please give me idea how can i process further.
    thanks a lot

    While duffymo is correct in regard to most major database products, it's my understanding (warning! wild-ass guess coming) that the Hypersonic DB is more "application-centric" and the dynamic creation of databases is part of its design. It's pure Java database software, and therefore is not appropriate for all database projects, in particular those that require extremely high-performance.
    See http://hsqldb.org/
    I've not used it yet (but soon though), and I can't really advise anyone about it.
    However, I'm wondering if you phrased you question in a way that is confusing us. To most of us in casual conversation, a "database" is both (1) a large organized collection of data and (2) the software that is used to organize and access it. However, the phrase "create a database" usually means creating a (1) database (a collection of data) using an already created (2) database software, such as Oracle, MySQL, DB2, HSQDB, etc., etc. If you'r question is, how do a create some new database software using Java, the answer is that this is a very very big and hard thing to do for the general case and probably not something you want to be doing.

  • How can I map an image (JPEG) from the SQL database image string

    I saved the image into SQL database, see attachment (SaveImage2SQLDB.rar), while I have some trouble to retrieve the image. I also attached the vi which I used to convert the string to image. The string already has a value I obtained from the database. Can anyone tell me the reason why it didn't work.
    Thanks in advance.
    Jane
    LabVIEW 2012, VDM 2012
    Attachments:
    convertstringtoimage.vi ‏78 KB
    SaveImage2SQLDB.zip ‏27 KB

    Hi Jane,
    What exactly isn't happening correctly?  The conversion or the retrieval? 
    This discussion forum may be of some use: http://forums.ni.com/t5/LabVIEW/image-from-compressed-string/m-p/2207894
    Matt S.
    Industrial Communications Product Support Engineer
    National Instruments

  • Retrieve image from my sql database using jsp

    I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)
    please give me some sample codes.

    PreparedStatement pst = null;
      ResultSet rs=null;
    pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");
    rs=pst.executeQuery();
    while(rs.next())
                                byte[] b=rs.getBytes("image");
                                FileOutputStream fos=new FileOutputStream("c://image.jpg");
                                fos.write(b);
                            } hi this the code to retrieve the image from DB and write to a file.

  • Problems generating multiple services from the same EAR using servicegen

    I have a single EJB JAR that contains multiple stateless session beans. I
    want to expose each of these individually as a service. So I have defined
    the following in my build file:
    <servicegen destEar="${ear.file}" warName="${war.file.name}"
    contextURI="web_services">
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="AService"
    serviceURI="/AService" includeEJBs="AService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="BService"
    serviceURI="/BService" includeEJBs="BService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="CService"
    serviceURI="/CService" includeEJBs="CService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="DService"
    serviceURI="/DService" includeEJBs="DService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="EService"
    serviceURI="/EService" includeEJBs="EService" generateTypes="True"
    expandMethods="True"/>
    </servicegen>
    I execute the task and it runs without issue. However, when I attempt to
    deploy the EAR I get some odd results (there are multiple jars listed all
    with my original name and then a number appended, for example MyApp.ear2).
    The deployment fails because each of these JARs contains the same session
    beans.
    So, I'm wondering if my only option is to package each session bean in a
    separate EJB JAR or if there is another way I could get this to work.
    Thanks,
    Rob

    Thanks, Neal. I'll do as you suggest.
    Just a little feature enhancement request, as well. It would be nice if the
    option existed to break out the webservices for all the session beans in a
    ejb rather than creating one all-encompassing interface of all the methods.
    I think this would be a useful feature.
    Thanks, again,
    Rob
    "Neal Yin" <[email protected]> wrote in message
    news:[email protected]...
    I am not sure what can cause this. But I will make servicegen check for
    duplicate.
    For now, in order to make sure your automatic build process, you can use
    ant's build in task "jar" to update your application.xml with a correctone
    after servicegen.
    -Neal
    "Rob Moore" <[email protected]> wrote in message
    news:[email protected]...
    Neal,
    After discussing this issue with a coworker, I found that when he buildsthe
    ear on his machine using the servicegen entries I specified previously,the
    application.xml is generated correctly. Mine, as you guessed, puts in
    multiple module entries all containing references to the same jar. I'm
    puzzled because we are apparently running in the same environment. Anyidea
    what might be causing it?
    Thanks,
    Rob
    "Neal Yin" <[email protected]> wrote in message
    news:[email protected]...
    Hi Rob,
    There is something wrong during generating application.xml for the
    ear.
    After servicegen, if you open generated application.xml, you probablycan
    see duplicate entries for one module. Please go ahead delete thoseredundant
    entries. Let me know if this works.
    -Neal
    "Rob Moore" <[email protected]> wrote in message
    news:[email protected]...
    I have a single EJB JAR that contains multiple stateless session
    beans.
    I
    want to expose each of these individually as a service. So I havedefined
    the following in my build file:
    <servicegen destEar="${ear.file}" warName="${war.file.name}"
    contextURI="web_services">
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="AService"
    serviceURI="/AService" includeEJBs="AService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="BService"
    serviceURI="/BService" includeEJBs="BService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="CService"
    serviceURI="/CService" includeEJBs="CService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="DService"
    serviceURI="/DService" includeEJBs="DService" generateTypes="True"
    expandMethods="True"/>
    <service ejbJar="${ejbc.jar.file}"
    targetNamespace="http://www.acme.com/xauto" serviceName="EService"
    serviceURI="/EService" includeEJBs="EService" generateTypes="True"
    expandMethods="True"/>
    </servicegen>
    I execute the task and it runs without issue. However, when I
    attempt
    to
    deploy the EAR I get some odd results (there are multiple jars
    listed
    all
    with my original name and then a number appended, for exampleMyApp.ear2).
    The deployment fails because each of these JARs contains the samesession
    beans.
    So, I'm wondering if my only option is to package each session bean
    in
    a
    separate EJB JAR or if there is another way I could get this to
    work.
    >>>>
    Thanks,
    Rob

  • How to read data from the excel file using java code.

    Hi to all,
    I am using below code to getting the data from the excel file but I can't get the corresponding data from the specific file. can anyone give me the correct code to do that... I will waiting for your usefull reply......
    advance thanks....
    import java.io.*;
    import java.sql.*;
        public class sample{
                 public static void main(String[] args){
                      Connection connection = null;
                          try{
                               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                               Connection con = DriverManager.getConnection( "jdbc:odbc:Mydsn","","" );
                               Statement st = con.createStatement();
                               ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
                               System.out.println("sample:"+rs);
                                  ResultSetMetaData rsmd = rs.getMetaData();
                                  System.out.println("samplersd:"+rsmd);
                               int numberOfColumns = rsmd.getColumnCount();
                                  System.out.println("numberOfColumns:"+numberOfColumns);
                                   while (rs.next()) {
                                            System.out.println("sample1:"+rs);
                                            for (int i = 1; i <= numberOfColumns; i++) {
                                                 if (i > 1) System.out.print(", ");
                                                 String columnValue = rs.getString(i);
                                                 System.out.print(columnValue);
                                            System.out.println("");
                                       st.close();
                                       con.close();
                                      } catch(Exception ex) {
                                           System.err.print("Exception: ");
                                           System.err.println(ex.getMessage());
                        }

    1: What is the name of the excel sheet?
    2: What is printed in this program? null ? anything?
    error?Excel file name is "sample.xls" I set excel file connectivity in my JDBC driver(DSN). Here in my program I am not giving that excel file name. I am giving only that excel sheet name. that is followed
    ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );The output of this program is given bellow.
    sample:sun.jdbc.odbc.JdbcOdbcResultSet@1b67f74
    samplersd:sun.jdbc.odbc.JdbcOdbcResultSetMetaData@530daa
    numberOfColumns:2

  • How to find out top 10 records from the R/3 using Java code (WD Program)

    Hi Experts,
    I have used Java Web Dynpro program to fetch records from the backend. Following code helps me and fetches record. As per the customer reqirement, we have to fetch only top 10 records (Actual Cost) from the backend. So I have to modify the Java code. How I can do so? Please help.
              wdContext.nodeGraphData().invalidate();
              IPublicCostcnt.IGraphDataElement categoryElement;
                   for (int i = 0; i < wdContext.nodeItab_Final1().size(); i++) {
                   categoryElement = wdContext.createGraphDataElement();
                   categoryElement.setCostElement(""+ wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getDescription());
                   categoryElement.setActualCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getActual_Cost().toString());
                   categoryElement.setPlannedCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getPlan_Cost().toString());
                   wdContext.nodeGraphData().addElement(categoryElement);
    Regards,
    Gary

    Dear SDN Users,
    This is how I resolved the issue.
    1) Requested ABAPer to provide me sorted data. The data has been sorted in descending order of actual_cost.
    2) After that I used following code. This resolved the issue.
         if (wdContext.nodeItab_Final1().size()>10){
         IPublicCostcnt.IGraphDataElement categoryElement;
              for (int i = 0; i < 10; i++) {
              categoryElement = wdContext.createGraphDataElement();
              categoryElement.setCostElement(""+ wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getDescription());
              categoryElement.setActualCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getActual_Cost().toString());
              categoryElement.setPlannedCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getPlan_Cost().toString());
              wdContext.nodeGraphData().addElement(categoryElement);
         if (wdContext.nodeItab_Final1().size()<=10){
         if (wdContext.nodeItab_Final1().size()>0){
         IPublicCostcnt.IGraphDataElement categoryElement;
              for (int i = 0; i < wdContext.nodeItab_Final1().size(); i++) {
              categoryElement = wdContext.createGraphDataElement();
              categoryElement.setCostElement(""+ wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getDescription());
              categoryElement.setActualCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getActual_Cost().toString());
              categoryElement.setPlannedCost(wdContext.nodeItab_Final1().getItab_Final1ElementAt(i).getPlan_Cost().toString());
              wdContext.nodeGraphData().addElement(categoryElement);
    Regards,
    Gary

  • How to read and write from the serial port using java

    can anyone tel me how to capture data from a serial port and display on the screen and also store it in a database.

    Java Comm API, JDBC

  • Read the c2 log file of the sql server using java

    Hi All,
    i want to read the c2 log file using the core java. how is it possible ? if anybody knows about this please give me the sample code to help me.
    i am also searching on net but i am not getting any result about this? so please help me to doing this task?
    awaited person

    Hi All,
    i want to read the c2 log file using the core java. how is it possible ? if anybody knows about this please give me the sample code to help me.
    i am also searching on net but i am not getting any result about this? so please help me to doing this task?
    awaited person

  • How do I obtain the next number for a Primary Key using an ADF View Object?

    I have two separate View Objects (A & B) for the same Entity Object. View Object A does a SELECT on all of the fields in the table. This View Object is where I execute my adds and updates. View Object B is only used to retrieve the next number for the primary key. This is done so that when I add a row to the database, I always get the max number of the primary key and add one to it. I accomplished this by setting the SQL mode to Expert and using the SQL: "SELECT MAX(NBR) AS MAX_NUMBER FROM TABLE_1". This may be overkill having a seperate View Object for this, but so far this is the only way I have found to obtain the next number. However, I have discovered that this way does not always work.
    The problem I'm running into is when I try to add multiple records to View Object A without committing the transaction between each add. Because View Object B is disconnected from View Object A, the MAX_NUMBER of View Object B comes back with the same number for each add I do on View Object A. So I know I must retrieve the MAX_NUMBER from View Object A.
    I've tried using the following code in my Table1ViewImpl class:
    this.setQuery("SELECT MAX(Table1.NBR) AS MAX_NUMBER FROM TABLE_1 Table1");
    this.executeQuery();
    The view object now has what I want, but I have yet to figure a way to extract the MAX_NUMBER out of the View Object. I've also looked into using the method addDynamicAttribute() but I can't figure out any way to set the attribute with the MAX_NUMBER.
    I can't be the only one trying to retrieve the next number from a database table using ADF. Can anyone help me with this? FYI - I'm using JDev 10.1.3 EA.

    You missing the point.
    On a multi-user db knowing the next highest number doesn't guarantee the number will be available when it comes time to commit the record. You can prove this to yourself by opening two instances of your app and do whatever you do to add a new record to your VO. Both will assume the same number, and when you commit an error will be generated
    You must use sequences to avoid the possibility of duplicate keys. If you are trying to avoid gaps in your numbering then you need to convince yourself why this is necessary.

  • Can Audit Vault be used for getting detailed read type information from the siebel database?

    Can Audit Vault be used for getting detailed read type information from the siebel database?

    Kramer wrote:
    saurabh wrote:
    check below cmd to see where archive are generated.
    SQL> archive log list
    And also check the following
    SQL> select flashback_on from v$database;
    Hi
    Here is the out put
    SQL>  select flashback_on from v$database;
    FLASHBACK_ON
    NO
    SQL>  archive log list
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence     11
    Next log sequence to archive   12
    Current log sequence           12
    The flashback is not enabled. But archive log list shows archive destination is specified to use_db_recovery_file_dest.  And I checked the log_archive_dest_10 still empty
    Flashback off or on has nothing to do with it. 

  • JAVA, sqlserver - Need to load an image from the sql server database

    hi,
    I need to load an image from the sql server database using java. I have connected to the database and getting all other records except the records for a photo (datatype = LONGVARBINARY) and Remarks (datatype = LONGVARCHAR).
    I am using java and sql server db. The photo and remarks are stored in the db. and i need to show the image and the remarks fetching them from there.
    I get the error :
    Thread-9 org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
    How can I achieve this?
    Thanks,
    Gargi

    Exactly. And are you using MySQL?
    No. You are using Microsoft SQL server if I have to believe your initial post. A quick google tells me that the dialect class to use is:
    org.hibernate.dialect.SQLServerDialect

  • SharePoint 2013 - Server Error in '/' Application - This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database

    Hi
    After I ran SharePoint configuration wizard successfully to upgrade to SharePoint 2013 / SP1.
    I can open Central Administration site just fine.
    but now when I open any Site collection,  I got this error.
    Server Error in '/' Application
    This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration
    Wizard, located on the Start menu in Microsoft SharePoint 2010 Products
    I have restarted all the servers:  SQL server, WFE and APP servers but still cann't get this resolve.
    Services on all servers are running,  IIS - application pools are running.
    Can someone help with where that could be a problem or if there is a solution.
    Thanks in advance for your comments or advices.
    Swanl

    Please verify the followings:
    Make sure that from the SharePoint front end and application servers that you can ping your SQL server.
    Make sure that your Farm account has permission to the configuration database.
    Lastly verify that your database didn't for some reasons go into recovery mode.
    once everything is fine and you are still having issues, restart the SQL host service on the SQL server.
    Once the service is restarted you will need to reboot Central Admin and then your front end servers.
    In addition, as you built your farm inside the firewall, please disable the firwall, or create rules for SQL Server service in the firwall on SQL server.
    More information about creating rules in firewall, please refer to the following posts: http://social.technet.microsoft.com/Forums/en-US/c5d4d0d0-9a3b-4431-8150-17ccfbc6fb82/can-not-create-data-source-to-an-sql-server http://www.mssqltips.com/sqlservertip/1929/configure-windows-firewall-to-work-with-sql-server/
    Here is a similar post for you to take a look at: http://social.technet.microsoft.com/Forums/en-US/ea54e26c-1728-48d4-b2c5-2a3376a1082c/this-operation-can-be-performed-only-on-a-computer-that-is-joined-to-a-server-farm-by-users-who-have?forum=sharepointgeneral 
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • When i tap a name in favorites it uses the number from the name below the one i want

    when i tap a name in iphone favorites it uses the number from the name below it

    Try this:
    First, turn FaceTime off in Settings>Phone. Then, delete all of your favorites entries. Next, turn FaceTime back on, then add all of your favorites back.

  • How to get page number from the PDF using Javascript

    Hi,
    We are having list of Single page PDF. The pdf are named in the order,
    ISBN_Author_01.PDF  (with real page number as i)
    ISBN_Author_02.PDF  (with real page number as ii)
    ISBN_Author_03.PDF  (with real page number as iii)
    ISBN_Author_04.PDF  (with real page number as 1)
    ISBN_Author_05.PDF  (with real page number as 2)
    ISBN_Author_06.PDF  (with real page number as 3)
    ISBN_Author_nn.PDF  (with real page number as 500)
    Here each pdf has a page number and in sequential order.
    The task is to check whether all the pdfs are in sequential order (i.e i, ii, iii, 1, 2, 3). If any page is missing, the script should throw an error report.
    To do this task, I am writing a Javascript to get the real page number from the PDF.
    Can anybody help me how to get the page number from the PDF using Javascript.
    Thanks,
    Gopal

    The "real" page number within a PDF is the count of the physical page starting at 0, zero.
    pageNum numPages
    The number printed on each page is the page label.
    setPageLabels  getPageLabel
    You will have to open each PDF and your script would need to know the page label for that file. I would expect you would need to build a 2 dimensional  array of the file names and the page label for the page within that array.

Maybe you are looking for