Fixed length retrieval using JDBC

Hi All,
I am wondering if there is an api where I can manipulate the result of a preparedstatement query.
I am using a standard JDBC Connection to query against an oracle database. The particular column I retrieve is a decimal and can vary in length (i.e. 0.1, 125.005, 20.51..etc.) What I need is a fixed length of 12 places before the decimal, and 6 places after the decimal.
So for my above examples:
0.1 should be 000000000000.100000
125.005 should be 000000000125.005000
20.51 should be 000000000020.510000
Is there an easy way of doing this after I get the result back? The result is a String. Any ideas would be much appreciated. Thanks

So, you want to convert a number to a String. Use a DecimalFormat object to do that.

Similar Messages

  • Exporting to fixed length text using Crystal Enterprise 10

    Post Author: adamsueryan
    CA Forum: Deployment
    I would like to know if it is possible to export from Crystal Enterprise 10 to a fixed length text file similar to the text exporting option using Crystal Reports 8.5.  From Enterprise 10 I see you can export to Rich Text Format but that is not really the same.
    Adam

    Post Author: hamish_sco
    CA Forum: Exporting
    I normally use these settings, which work pretty well; Excel Format:  CustomOptions:  Column width based on - Detailsthen the following boxes ticked;Export Object FormattingMaintain Relative Object PositionMaintain Column AlignmentExport Page Header and Footer CheersHamish

  • Fixed Length records using SQL

    hi , using the following code in a file that generates an output file with a fixed length 300 character lines.
    SPOOL C:\PHONE_SAMPLE.OUT;
    SET HEADING OFF;
    SET PAGES 0;
    SET ECHO OFF;
    SELECT rpad(CONTACT_ID,15),rpad(PHONE1,15),rpad(PHONE2,15),rpad(PHONE3,15),rpad(PHONE4,15),rpad(PHONE5,15),rpad(PHONE6,15)
    ,rpad(CALLSEQ,6),rpad(NDCALLSEQ,6),rpad(LANG,3),rpad(FIRST,25),rpad(LAST,25),rpad(CONCODE,10),rpad(EMAIL,30),rpad(TXTMSG,20),rpad(WVEND,20),
    rpad(APPTSTART,14),rpad(APPTEND,14),rpad(APPTTYPE,10),rpad(APPTLOCTION,10),rpad(FILLER,1)||'\n'
    FROM PHONE_SAMPLE;
    SPOOL OFF;
    After I run this I get my data and the following below - my end of Character line, and then "22 rows selected" - How do I remove the 22 rows selected. and stop at \n. Any help appreciated.
    Is it a set command I am missing ?
    \n
    22 rows selected.

    Hi,
    SET FEEDBACK OFF
    And you don't need SET HEADING OFF when you have SET PAGES 0
    And you don't need to end SET commands with ';' since they are SQL*Plus commands
    Regards
    Peter

  • Help with FIXED LENGTH columns - using spool command

    Hi guys,
    I have a view I am trying to spool using fixed length columns, and the spacing is off. Ive tried numerous things such as specifiying the column width before running the query, using the rpad command, but nothing seems to work. I have to spool it to a text file in order for the users to import this file into another system. I would welcome any and all suggestions. Thanks so much. The following is the view:
    SELECT "EMPLOYEE_ID","FIRST NAME","INITIAL","LAST NAME","SUFFIX","TRAINING DATE","Course ID","Class ID", "We", "Make / Model", "Cali", "Barrell", "Serial Number", "Qualification", "Application", "SCORE", "Status", "Add Time", "Record Add ID","Record Add Date","Record Change ID","Record Change Date","RN" FROM
    (SELECT
    UPPER(RPAD(tbl.ssn,10)) AS "EMPLOYEE_ID",
    UPPER(RPAD('',12)) AS "FIRST NAME",
    UPPER(RPAD('',1)) AS "INITIAL",
    UPPER(RPAD('',20)) AS "LAST NAME",
    UPPER(RPAD('',5)) AS "SUFFIX",
    UPPER(RPAD(to_char(QUALDATE, 'mmddyyyy'),8)) AS "TRAINING DATE",
    UPPER(RPAD('P123',8)) AS "Course ID",
    UPPER(RPAD('',6)) AS "Class ID",
    UPPER(RPAD('P',4)) AS "We",
    UPPER(RPAD('',4)) AS "Make / Model",
    UPPER(RPAD('',4)) AS "Cali",
    UPPER(RPAD('',7)) AS "Barrell",
    UPPER(RPAD('',15)) AS "Serial Number",
    UPPER(RPAD('A',4)) AS "Qualification",
    UPPER(RPAD('D',4)) AS "Application",
    to_char((RAWSCORE/250)*100, 'fm000.00') AS "SCORE",
    UPPER(RPAD('PASS',4)) AS "Status",
    UPPER(RPAD('',8)) AS "Add Time",
    UPPER(RPAD('',8)) AS "Record Add ID",
    UPPER(RPAD('',8)) AS "Record Add Date",
    UPPER(RPAD('',8)) AS "Record Change ID",
    UPPER(RPAD('',8)) AS "Record Change Date",
    row_number()over(partition by firearms_scores.ID_NUMBER order by QUALDATE desc ) rn
    FROM FIREARMS_scores, TBL
    where scores.id_number=tbl.id_number
    and qualyear='2010' and coursecode='SA'
    order by employee_id)
    where rn =1

    Hi,
    You RPAD doesn't do anything, since they are same as:
    SQL> SELECT NULL AS "Record Add ID",
      2         NULL AS "Record Add Date",
      3         NULL AS "Record Change ID",
      4         NULL AS "Record Change Date" FROM DUAL;
    R R R R
    SQL>Can't see why COLUMN command shouldn't do what you want. Maybe you forgot the double quotes?
    SQL> COL "Record Add ID" FOR a18
    SQL> COL "Record Add Date" FOR a18
    SQL>
    SQL> SELECT NULL AS "Record Add ID",
      2         NULL AS "Record Add Date",
      3         NULL AS "Record Change ID",
      4         NULL AS "Record Change Date" FROM DUAL;
    Record Add ID      Record Add Date    R R
    SQL>P.S: You probably shouldn't set a column width which is smaller than the header length
    Regards
    Peter

  • Handling any query using JDBC ?

    Hi there,
    I was wondering if their actually exist a way of handling/processing any SELECT statement a user would enter.
    ex: the user enter SELECT * FROM SCOTT.EMP;
    Is it possible to retrieve using JDBC teh metadata associated with "*" ?
    any help would be welcome.
    Regards
    Eric.

    When you get back the result of a query in JDBC you get a ResultSet object.
    Off of that you can obtain a ResultSetMetaData object which fully describes the result set - column names, types, scale and precision, etc. You can use that for dynamic processing of your result set, for example if you wanted to display it in a table.

  • How to store and retrieve image in a MsAccess DB using JDBC

    I want to store images in a MsAccess DB using JDBC and also want retrieve them from DB. please don't tell to store the path of image..I want to store the image not the path...pls reply..thanx in advance

    zakircse, you should read more about Java's API.
    import java.io.*;
    import java.sql.*;
    import java.util.Properties;
    import java.awt.*;
    import javax.swing.*;
    public class ImageDemo{
    public static void main(String argv[]){
    try{
    String url="jdbc:access:/c:/test";
    Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();
    Properties properties=new Properties();
    Connection connection = DriverManager.getConnection(url,properties);
    Statement stmt = connection.createStatement();
    stmt.execute("create database if not exists imagedatabase;");
    connection.setCatalog("imagedatabase.mdb");
    stmt.execute("create table if not exists imagetable (imageid int,IMAGE_DATA blob);");
    File file=new File("c:/pic.jpg");
    FileInputStream in=new FileInputStream(file);
    PreparedStatement ps=connection.prepareStatement("insert into imagetable (imageid,IMAGE_DATA) values(?,?);");
    ps.setInt(1,1234);
    ps.setBinaryStream(2,in,(int)file.length());
    ps.execute();
    ps.close();
    ResultSet rs =stmt.executeQuery("select IMAGE_DATA from imagetable where imageid=1234");
    byte[] imgbytes=null;
    if(rs.next()) {
    imgbytes=rs.getBytes(1);
    rs.close();
    stmt.close();
    connection.close();
    if(imgbytes!=null){
    JFrame fr = new JFrame();
    fr.setTitle("Simple Demo for Load Image from MS Access");
    Image image = fr.getToolkit().createImage(imgbytes);
    fr.getContentPane().add(new PaintPanel(image));
    fr.setSize(200,400);
    fr.setVisible(true);
    Thread.sleep(10000);
    System.exit(0);
    catch( SQLException sqle )
    do
    System.out.println(sqle.getMessage());
    System.out.println("Error Code:"+sqle.getErrorCode());
    System.out.println("SQL State:"+sqle.getSQLState());
    sqle.printStackTrace();
    }while((sqle=sqle.getNextException())!=null);
    catch( Exception e )
    System.out.println(e.getMessage());
    e.printStackTrace();
    class PaintPanel extends JPanel {
    private Image image;
    public PaintPanel(Image image) {
    this.image = image;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(image, 0, 0, this);
    }

  • Flat file with fixed lengths to XI 3.0 using a Central File Adapter---Error

    Hi
    According to the following link
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    In Adapter Monitor I got the following error,
    In sender Adapter,
    Last message processing started 23:47:35 2008-10-25, Error: Conversion of complete file content to XML format failed around position 0 with java.lang.Exception: ERROR converting document line no. 1 according to structure 'Substr':java.lang.Exception: Consistency error: field(s) missing - specify 'lastFieldsOptional' parameter to allow this
      last retry interval started 23:47:35 2008-10-25
      length 15,000 secs
    some one help me out ?
    Thanks
    Ram

    from the blog you referenced -
    <u> /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    <b>goto step 4</b>
    <u>additional parameters</u>
    add as the last entry
    <recordset structure>.lastFieldsOptional            Yes
    e.g.,
      Substr.lastFieldsOptional            Yes

  • Send a flat file with fixed lengths to XI 3.0 using a Central File Adapter?

    Hello,
    I'm wondering if someone have experience setting up conversion for different record structures. The example shown,
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter,
    (in a greate way) only picture one kind of structure.
    How should it be done if the file would contain
    10Mat1
    20100PCS
    The first record structure has columns
    ID(2),Material(10)
    The second redcord structure has columns
    ID(2),Quantity(3), Unit of messure (3)
    Brgds
    Kalle
    Message was edited by: Karl Bergstrom

    The configuration would be like follows:
    Content Conversion Parameters:
    Document Name: <your message type name>
    Document Namespace: <your message type namespace>
    Document Offset: <leave empty>
    Recordset Name: <any name>
    Recordset Namespace: <leave empty>
    Recordset Structure: row1,,row2,
    Recordset Sequence: any
    Recordsets per Message: *
    Key Field Name: ID
    Key Field Type: String
    Parameters for Recordset Structures:
    row1.fieldNames           ID,Material
    row1.fieldFixedLengths    2,10
    row1.keyFieldValue        10
    row2.fieldNames           ID,Quantity,UOM
    row2.fieldFixedLengths    2,3,3
    row2.keyFieldValue        20
    Instead of row1 and row2 you can choose any name.
    Regards
    Stefan

  • How to process file with fixed length using MFL in OSB

    Hi Team,
    I need to translate this file using MFL. its fixed lenght[each line is having 81 chars] file in below format.
    Please help me to process this in OSB using MFL.
    ==================================================================
    START
    [email protected]
    [email protected]
    END
    Subject : CALIFORNIA STEEL IND Renege #00424523 Hse580 CTH580
    BODY:
    User_ID: LARRY014
    Xpd2 Hse/Customer # : 580/1196310
    Xpd Order Number: 580094624
    Customer E-Mail: [email protected]
    Customer E-Mail 2:[email protected]
    Customer Phone : 9093506458
    Dear Salesperson,
    gexprosupply.com Order # : 00424523
    gexprosupply.com User ID : LARRY014
    Customer CALIFORNIA STEEL IND has entered order 00424523
    through gexprosupply.com.
    THIS ORDER HAS RENEGED for the following reason(S):
    I. ORDER LEVEL
    NOTE SEGMENTS FOUND IN INPUT - SENTRY
    CDF REQUIRED CUSTOMER - ORDER RENEGED
    II. ITEM/LINE LEVEL
    LINE # ECOM LINE NAED QTY STATUS ALLOW SUBS
    Please resolve the renege and release the order in Sentry
    01 as soon as possible. Thank you.
    EMAIL-END
    ==================================================================
    Thanks
    Reddy
    Edited by: 913248 on Feb 8, 2012 2:07 PM
    Edited by: 913248 on Feb 8, 2012 2:08 PM

    Hi Prabu,
    thanks a lor fro you replay.......
    the above file is having mail content[from id, to id, subject and body] i need to read this file using OSB and need to sent to the respective email id.
    the file format is :
    it will have
    0- its a fixed length in each line [81 chars]
    1--"START" tag....starting of the email
    2--after START, the email ID is "FROM" email ID
    3-after "FROM" emailid, 3rd line onwards....will have "TO email IDs
    4-"END"---end of the email IDs
    5- "Subject " ...will have subject of the email
    6-"BODY".... the email body will start in this tag
    7-"EMAIL-END"..end of the email....
    so my requirement is ..i need to read above file in OSB and send notification emai.
    Thanks
    Reddy

  • Retrieving sdo_geometry using JDBC

    Hi all. I have a simple program running in JDeveloper using JDBC for retrieving SDO_Geometry values from various spatial tables. The program works fine but when I run SQL statements in order to retrieve the geometry columns from the spatial tables the program is returning the sdo_geometry values in an oracle.sql.STRUCT format. For example if I set up the following SQL query to retrieve an sdo_geometry column from a table states, it returns the results below:
    spatialQuery = "select a.geom from states a;"
    oracle.sql.STRUCT@e2dae9,
    oracle.sql.STRUCT@19209ea,
    oracle.sql.STRUCT@c8f6f8,
    oracle.sql.STRUCT@1ce2dd4,
    oracle.sql.STRUCT@122cdb6,
    I know the program works but I am lost in understanding these results. Can anyone tell me how to interpret these results or even how to translate them into a more useful format. All I want is the sdo_geometry values back!
    Cheers Joe

    If you scroll to the top of the page in the link posted previously you'll read the following
    Some DatabaseMetaData methods take arguments that are String patterns. These arguments all have names such as fooPattern. Within a pattern String, "%" means match any substring of 0 or more characters, and "_" means match any one character. Only metadata entries matching the search pattern are returned. If a search pattern argument is set to null, that argument's criterion will be dropped from the search.

  • Store, Retrieve and Display picture or video to/from DB2 using JDBC

    I need an idea for implementing the"Store, Retrieve, Display Image/Video" concept in JDBC. My Database is DB2. I could not get proper info from google.
    Thanks and Regards
    Muthukris Bala

    Muthukris wrote:
    I need an idea for implementing the"Store, Retrieve, Display Image/Video" concept in JDBC. My Database is DB2. I could not get proper info from google.
    1. Figure out how to display image/video
    2. Figure out how to encode/decode a image/video into a byte array
    3. Design a database suitable for your application that stores blobs
    4. Figure out how to use JDBC to store/retrieve blobs via byte arrays.
    Steps 1 and 2 have nothing to do with this forum (nor GUI code). There is at least on forum on this site that deals with questions about that.
    Steps 3 is only somewhat related to this forum. A DB2 forum would be best.
    Step 4 is the only part of this that is specific to this forum. And if you have not used any JDBC then you first start with the tutorial or some other suitable method to learn how JDBC works before attempting blobs.

  • Retrieving data from Microsoft Access using JDBC

    I noticed that when i tried retrieving data from Microsoft access using JDBC, I realised that it was throwing SQLException when the column names were two word with spaces between them, e.g. Date Birth. But after i removed the space from the column names, my SQL queries were retrieving data. Was it because of the space in between the column names of the table?

    Yeah, as far as I know having two word column names isn't allowed in SQL. There might be some way to escape it, but generally it's sensible to avoid it.

  • How do you retrieve a Collection of objects using JDBC?

    How do you retrieve a Collection of objects using JDBC.
    MORE INFO:
    I have created a class i.e. Account class and I want to retrieve all the accounts previously created for accounts in my Mysql database..
    my method would retrieve an array of Account instances in the database i.e.
    public Vector retrieveAccounts();

    Connection con = null;
    ArrayList accounts = new ArrayList();
    try{
      con = DriverManager.getConnection(...);
      PreparedStatement ps = con.prepareStatement("select * from accounts");
      Resultset rs = ps.executeQuery();
      while (rs.next()) {
        Account account = new Account(rs.getString(1), rs.getString(2), ...);
        accounts.add(account);
      Account[] account_array = new Account[accounts.size()];
      accounts.toArray(account_array);
    catch (SQLException sqle) {
       sqle.printStackTrace();
    finally {
      if (con != null) {
        con.close();
    }should pretty much to what you want, you will obviously need to change it so that, a) the SQL query is correct and b) the Account class is correct and c) the correct values are taken from the result set to create an account.

  • Is there a way to retrieve data from database wihout using JDBC while using JPDK?

    Hi,
    I want to create a portlet using JPDK with extra render modes and edit/Edit defaults mode too. The detail and show renderer mode jsp's/servlets render data from database. Based on the personalized paramter, the data rendered in detail and show mode will be obtained from database.
    The articles in the PDK zip asks not to use JDBC for security vulnerability. Does that mean , I should not use JDBC to connect to db to get data. If not, what should I use ? How do I connect to database ? Is there any class which helps to connect to db without using JDBC ?
    thanks,
    Mainak

    I'm not sure what articles you are refering to, because there is no other way to access a database from a java program. Generally, security related docs tend to be a little paranoid (and so they should be), but you have to balance high security against getting the job done.
    Obviously, if using JDBC, you need to be careful about protecting your config files because they will contain connection information.

  • Retrieving Schema details from any database using JDBC.

    Hi,
    We are in a process of developing a tool to extract the schema level details from any database. Following are the areas where we are facing difficulties. Please give us your valuable comments.
    1.How can I get all the depending views of a particular table or vice- versa ?
    2.If there is a join view in my database.How can i get the information
    for all the join columns?
    3. suppose the view in the database is built using some select and omit
    Clause. how can I get those conditions using JDBC ?
    4.for a viewcolumn , how can I find out, it refers to which column of
    a table ?
    5.For a table how can I get the information about its unique
    constraints and check constraints
    6.How can I check , a constraint is enabled or disabled on any table?
    I will appreciate your response.

    Hi,
    We are in a process of developing a tool to extract
    ct the schema level details from any database.
    Following are the areas where we are facing
    difficulties. Please give us your valuable comments.
    1.How can I get all the depending views of a
    particular table or vice- versa ?No way with JDBC. You need to create something DBMS specific
    2.If there is a join view in my database.How can i get
    the information for all the join columns?see 1)
    3. suppose the view in the database is built using
    some select and omit
    Clause. how can I get those conditions using JDBC
    BC ?see 1)
    4.for a viewcolumn , how can I find out, it refers to
    which column of a table ?see 1)
    5.For a table how can I get the information about its
    unique constraints and check constraintsThe DatabaseMetadata object can return that information
    6.How can I check , a constraint is enabled or
    disabled on any table?I don't think that this is possible with JDBC (not sure
    if that information is returned from the DatabaseMetadata
    object). You will need to code something DBMS specific
    I think there is something with deferred constraints which
    can be checked by JDBC but I'm not sure about that either
    Thomas

Maybe you are looking for

  • Error while creating a webservice model

    Hi All,     I am doing the EMail WebService exercise. While creating the webservice model I select the UDDI or URL Radio button and in the wsdl field I paste the following url : http://www.abysal.com/soap/AbysalEmail.wsdl . When I click next in the p

  • F4IF_INT_TABLE_VALUE_REQUEST output language change

    Hi experts, I am buidling an internal table data in english language but when I click F4 on the specified field at run time , I am getting output pop-up data in different language seems like korean. Even the return code from 'F4IF_INT_TABLE_VALUE_REQ

  • Java L&F: html on jlabel *always* bold

    I'm trying to use HTML with a JLabel that is serving as a JTable cell editor. The UI default for the table and its cell renderers in the Java L&F (as well as most other L&Fs) is NOT bold. Is there some way to use HTML and not have it rendered as bold

  • Embedding Java Applet in Oracle Form

    I'd like to embed Java applet in Oracle Form. Please someone help me..let me know how to do it. Also I need to know how'll I use a jar within Oracle. Please help. Regards Rashed

  • Calling dll in Java using The JACOB Project

    Hi I'm trying to import and read the class and methods from a DotNet API (dll) in java code usind the Jacon Project does anybody know how to do it? (like and example or simple staps to have an idea) thanks Luca