Mapping SQL data types (especially SMALLINT) to Java classes

I want to know the reason for a certain pair of exceptions in JDBC�s mapping of SQL data types to Java classes.
Sun�s web site ( http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/mapping.html ), Sybase�s site, and other sites contain mappings from SQL data types to Java primitive data types and/or Java classes. On that Sun web page, Section 9.9.1 maps mostly to Java primitive data types, and Section 9.9.3 maps mostly to Java classes. For the SQL data types that map to both primitive data types and classes, the class is typically the wrapper class of the primitive data type. For example, SQL�s DOUBLE data type maps to both the double primitive data type and its wrapper class (Double). However, Section 9.7 of that Sun web page says that there are exceptions for SQL�s TINYINT and SMALLINT. As expected, they map to the byte and short primitive data types, but they map to the Integer class, not the Byte and Short classes (which are the wrapper classes for byte and short). The web page does not state the reason for this pair of exceptions. It seems to me that SMALLINT data would either work for both short and Short or fail for both short and Short. I don�t see why it would work for short but fail for Short (as the web page implies).
Can anybody think of a reason for the pair of exceptions? Thanks.

ghs wrote:
1) If a DBMS deals with the short and byte primitive data types (as the various web pages imply that it does), then why would it not deal with the Short and Byte wrapper classes?As another guess, because conversions get a little weird in java. Or at least they did in the past. As I recall (with not a lot of clarity) it is possible to do something like pass a perfectly valid string value into a short and get an exception. Whereas using Integer and then converting to Short works.
Keep in mind that these are guesses.
3) What I really want to know is this: If I use wrapper classes of Short and Byte (instead of Integer), what will be the harmful consequences (IF ANY)? So far, I have done some trivial testing with a Short for a SMALLINT column (I have not yet tried any TINYINT columns), and it seems to be working.I considered it risky to not test all target databases and drivers.
Obviously testing will reveal problems.
If you don't want to test then you might want to stick with integers.

Similar Messages

  • EJB/SQL data type mapping

    Is there a way to define the mapping between SQL data types and the generated Entity bean data types.
    (SQL server tiny int is getting mapped to a boolean!!! so I want to change it to a small, is there anything in the EJB 2.0 specification that defines the mapping between DB and EJB types).
    thx,
    sanjay.

    I haven't done any bottom up beans but I would imagine there is an equivalent way you can change the mapping to change the data type when the bean is created. You may just have to change the datatype on the imported db schema before you generate the beans. You will also need to check that your jdbc driver supports transformation between tinyint and small.

  • Not able to map extension data type in standard namespace.

    Hi guys,
    I have a customer who has this problem.  I am from the Business Partner area and BP supports XI for data exchange.  We provide standard message types in XI which contains core BP fields in ABA namespace.  Corresponding complex structure exists in the ABAP system.
    Now, the customer has created an enhancement data type for one of the data types present in the standard message type.  This enhancement data type is present in another namespace.  The customer has also generated the proxy for this enhancement data type which automatically created an Append structure to the standard complex structure in ABAP.
    Now, from the ABAP side all the data is extracted including the enhancement data into the complex structure.  In one of the outbound function modules, we call XI passing this data in complex structure.  However, we call XI in ABA namespace.  So, in XI, since the ABA namespace does not contain the enhancement data type, the customer is not able to map this to his target.  Even though we send all the data from ABAP to XI, since we call it in ABA namespace, the enhancement data is lost.
    So, is there any way of mapping this enhancement data also in ABA namespace itself.  Or from the ABAP, should I call the namespaces seperately.  This means, first I will call ABA namespace to map all standard fields.  Then, I call customer specific namespace to map enhancement data type.
    I would really appreciate a help over here since its a very important customer for SAP.
    Many thanks,
    Vikram

    I thing for customer mapping you have to do an mapping in our own namespace.
    than you need a copy of the fb BUPA_OUTBOUND_MAIN an also from fb
    ABA_BUPA_CALL_PROXY.
    in the copy of ABA_BUPA_CALL_PROXY you can call your own proxy
    do to changing this line
    DATA : lo_ababusiness_partner_out TYPE REF TO co_ababusiness_partner_out ."XI.3.0
    to
    DATA :lo_ababusiness_partner_out  TYPE REF TO yourproxy_mt
    see also weblog /people/michal.krawczyk2/blog/2006/11/14/xipi-data-type-enhancements-standard-business-partner

  • What is native Sql data types and does oracle support this?

    what is native Sql data types
    Does oracle support this?

    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#g31099

  • [svn] 1455: add sql date types and custom serialization tests

    Revision: 1455
    Author: [email protected]
    Date: 2008-04-29 11:56:59 -0700 (Tue, 29 Apr 2008)
    Log Message:
    add sql date types and custom serialization tests
    Modified Paths:
    blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/remotingService/dataTypes/DateTy pesTest.mxml
    Added Paths:
    blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/remotingService/dataTypes/MyFile Ref.as
    blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/remotingService/dataTypes/Proper tyProxyTest.mxml
    blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/remotingService/dataTypes/SQLDat eTypesTest.mxml

    Congrats to Shanky and Durval!
     SQL Server General and Database Engine Technical Guru - June 2014  
    Shanky
    SQL Server: What does Column Compressed Page Count Value Signify
    in DMV Sys.dm_db_index_physical_stats ?
    DB: "Interesting and detailed"
    DRC: "• This is a good article and provides details of each and every step and the output with explanation. Very well formed and great information. • We can modify the create table query with “DEFAULT VALUES". CREATE TABLE [dbo].[INDEXCOMPRESSION](
    [C1] [int] IDENTITY(1,1) NOT NULL, [C2] [char](50) NULL DEFAULT 'DEFAULT TEST DATA' ) ON [PRIMARY]"
    GO: "Very informative and well formed article as Said says.. Thanks for that great ressource. "
    Durval Ramos
    How to get row counts for all Tables
    GO: "As usual Durva has one of the best articles about SQL Server General and Database Engine articles! Thanks, buddy!" "
    Jinchun Chen: "Another great tip!"
    PT: "Nice tip" 
    Ed Price: "Good topic, formatting, and use of images. This would be far better if the examples didn't require the black bars in the images. So it would be better to scrub the data before taking the screenshots. Still a good article. Thank you!"
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • I cant find(map) some data types

    Hello!
    I am doing some test using a Access and SQL Server databases in order to do the mapping of the data types that is offered using the "sun.jdbc.odbc.JdbcOdbcDriver" ,I am using jdk1.3 I have not downloaded any other driver .
    The thing is that I an MS ACCESS table that I have
    Memo Field
    OleObject Field
    Text Field
    DateTime Field
    Currency Field
    When I get thet metadata for that table and aquire the java.sql.Types for the Memo and OleObject Aceess Types I get LONGCHAR and LONGBINARY Java.sql.Types....but I can not find them in the Java API documentation!!!! Are they the same with LONGVARCHAR and LONGVARBINARY that are reffered in the Java API ?
    Am in loosing somthing here?
    Thanks in advance

    They are one and same. Have a look at, http://www.i-mech.com/docs/jdbc/tbl_21_7.html
    Sudha

  • How to access PL/SQL data types through JDBC

    Hi,
    We have stored procedures written in PL/SQL. These stored procs take both IN and OUT parameters. The parameter types are both regular datatypes like NUMBER, VARCHAR etc. So far so good. I know how to handle these data types.
    Some of the stored procs also use parameters that are defined as composite data types like %ROWTYPE or %RECORD. How would I set the values of these data types? Can I use the oracle extension - support for Oracle Objects to accomplish this. If so please let me know with an example. If not any other suggestions or help will be greatly appreciated.
    Thanks
    Karthik
    null

    JDBC (and SQLJ) only support SQL types as stored procedure arguments, not PL/SQL types.
    If your stored procedure uses a PL/SQL-only type, such as BOOLEAN, record types, or index-by tables, then you cannot call it from Java (or, for that matter, from other languages as well).
    There is one exception: scalar index-by table arguments have been supported since JDBC 8.1.7 in the JDBC-OCI driver (refer to the JDBC manual for specifics).
    One workaround is to create wrapper PL/SQL stored procedures that take SQL arguments and convert them to PL/SQL -and vice versa- and call the original PL/SQL stored procedures. For example, a record type could be exploded into individual arguments, or it could be converted into a SQL object type, index-by tables could be represented as SQL collection types, etc.
    You can find a small example of this in the back of the JPublisher manual, where an example is given how to call a PL/SQL stored procedure that takes BOOLEAN arguments.

  • How can I map CHAR jdbc type to the char java type

    Hi,
    I would like to make all changes in the DB schema file and use source
    generation tools as a process. Now I foound that JDBC integer type
    corresponds to the Java int type. But having:
    <column name="ACTIVATION_STATUS" type="char" not-null="true" size="1"/>
    The generated class field is of String type:
    class .... {
         private String activationStatus;
    What is the proper way to have it mapped to char type fixing schema file
    only?
    Thanks in advance,
    Anton

    Abe White wrote:
    I don't think any schema XML will reverse map to a char type. You'd
    have to create a reverse mapping customization properties file as
    described here:>
    http://www.solarmetric.com/Software/Documentation/latest/docs/ref_guide_pc_reverse.html#ref_guide_pc_reverse_custom
    Thank you,
    Anton

  • SQL Data Type Import

    Hello
    I would like to import the schema of table in SQL Server into XI Data Type
    is it possible?
    thx
    Shai

    If you can export to excel file, I have a tool convert it to datatype.
    Liang

  • Sql data type : int

    create table del_me_tab
    num int
    insert into del_me_tab values(09);
    commit;
    select * from del_me_tab; // gives 9
    I want to modify the data type for num ... so that when i store 09 ... i get 09
    Is there a way to do that

    Hi,
    Integer 09 is the same as integer 9 so you cannot do this. If you want to present this number in a certain way use the to_char function with a format mask.
    select to_char(<column_name>,'09') will give you your 09 for example.
    Check out the documentation:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions181.htm#sthref2303
    Rene

  • Sql type to Java class?

    I want to write a utility class to generate a java source file (bean) from out of the metadata of a database table. the metadata returns the column type as a java.sql.Types constant (int value). now, i want to map these int values to Java classes. (e.g. Types.INT => java.lang.Integer). Is there already such a method in the API or do i have to write my own switch ... case Types.INT ... result = Integer.class ... method?

    well, i wrote my own utility method to generate such beans:
         * Convert SQL type code to corresponding Java class.
         * @param sqlType One of java.sql.Types.xxx.
         * @return Class that corresponds to the given type.
        public static Class toClass(int sqlType) {
            Class result = null;
            switch (sqlType) {
            case Types.BIGINT :
            case Types.INTEGER :
            case Types.SMALLINT :
            case Types.TINYINT :
                result = Integer.class;
                break;
            case Types.BIT :
            case Types.BOOLEAN :
                result = Boolean.class;
                break;
            case Types.CHAR :
                result = Character.class;
                break;
            case Types.DATE :
            case Types.TIMESTAMP :
                result = java.util.Date.class;
                break;
            case Types.DECIMAL :
            case Types.DOUBLE :
            case Types.FLOAT :
                result = BigDecimal.class;
                break;
            case Types.NULL :
                result = null;
                break;
            case Types.LONGVARCHAR :
            case Types.VARCHAR :
            default :
                result = String.class;
                break;
            return result;
        }//toClass()
         * Create a Java bean (source file) to map a database table. The class name is the table name, the bean
         * properties are the table columns. Each column will result in a property with a corresponding set() and
         * get() method.
         * @param connection Database connection to load table from.
         * @param schema Schema to get tables for.
         * @param tableName Name of table to create the bean for.
         * @param className Name of Java class to create.
         * @param fileName Name of Java source file to create.
         * @throws SQLException, IOException
        public static void createTableBean(Connection connection, String schema, String tableName, String className, String fileName)
                throws SQLException, IOException {
            if (connection != null && tableName != null && fileName != null) {
                //read table columns:
                DatabaseMetaData dmd = connection.getMetaData();
                ResultSet resultSet = dmd.getColumns(null, "%", tableName, null);
                Properties props = new Properties();
                if (resultSet != null) {
                    while (resultSet.next()) { //for each table
                        String name = resultSet.getString("COLUMN_NAME");
                        int type = resultSet.getInt("DATA_TYPE");
                        props.setProperty(name, ""+type);
                    }//next table
                }//else: resultSet unavailable
                //create source file:
                File file = new File(fileName);
                StringBuffer sb = new StringBuffer();
                sb.append("/* $Header:$ */\n");
                sb.append("package TODO;\n\n");
                sb.append("/**\n");
                sb.append(" * Container class to store data of one record (row) of table '"+tableName+"'.\n");
                sb.append(" *\n");
                sb.append(" * @version $Revision:$ ($Date:$)\n");
                sb.append(" * @author $Author:$\n");
                sb.append(" */\n");
                sb.append("public class ");
                sb.append(className);
                sb.append(" {\n\n");
                Enumeration enum = props.keys();
                StringBuffer sb2 = new StringBuffer(); //methods
                StringBuffer sb3 = new StringBuffer(); //toString()
                while (enum.hasMoreElements()) {
                    String columnName = (String) enum.nextElement();
                    //change first character of column name to lower case:
                    String fieldName = columnName.substring(0, 1).toLowerCase() + columnName.substring(1);
                    String stype = props.getProperty(columnName, ""+Types.VARCHAR);
                    int type = (new Integer(stype)).intValue();
                    Class javaClass = toClass(type);
                    String typeName = "String"; //default
                    if (javaClass != null) {
                        String javaClassName = javaClass.getName();
                        int lastDot = javaClassName.lastIndexOf('.');
                        if (lastDot >= 0) {
                            typeName = javaClassName.substring(lastDot + 1);
                    //field:
                    sb.append("    /** ");
                    sb.append(columnName);
                    sb.append(" */\n");
                    sb.append("    private ");
                    sb.append(typeName);
                    sb.append(" ");
                    sb.append(fieldName);
                    sb.append(" = null;\n");
                    //toString() method:
                    sb3.append("        sb.append(\",");
                    sb3.append(fieldName);
                    sb3.append("=\");\n");
                    sb3.append("        sb.append(");
                    sb3.append(fieldName);
                    sb3.append(");\n");
                    //set method:
                    sb2.append("    /**\n");
                    sb2.append("     * Set ");
                    sb2.append(columnName);
                    sb2.append(".\n     *\n     * @param value ");
                    sb2.append(columnName);
                    sb2.append(" to set.\n");
                    sb2.append("     */\n");
                    sb2.append("    public void set");
                    sb2.append(columnName);
                    sb2.append("(");
                    sb2.append(typeName);
                    sb2.append(" value) {\n        ");
                    sb2.append(fieldName);
                    sb2.append(" = value;\n    }\n\n");
                    //get method:
                    sb2.append("    /**\n");
                    sb2.append("     * Get ");
                    sb2.append(columnName);
                    sb2.append(".\n     *\n     * @return ");
                    sb2.append(columnName);
                    sb2.append(".\n     */\n");
                    sb2.append("    public ");
                    sb2.append(typeName);
                    sb2.append(" get");
                    sb2.append(columnName);
                    sb2.append("() {\n");
                    sb2.append("        return ");
                    sb2.append(fieldName);
                    sb2.append(";\n    }\n\n");
                }//next column
                sb.append("\n\n");
                sb.append(sb2.toString()); //methods
                //overwrite toString() method:
                sb.append("    /**\n");
                sb.append("     * Overwrite super.\n");
                sb.append("     *\n     * @return String representation of the object.\n");
                sb.append("     */\n");
                sb.append("    public String toString() {\n");
                sb.append("        StringBuffer sb = new StringBuffer(super.toString());\n\n");
                sb.append(sb3.toString());
                sb.append("\n        return sb.toString();\n");
                sb.append("    }\n\n");
                sb.append("}//"+className);
                //write to file:
                String text = sb.toString();
                BufferedWriter bw = null;
                try {
                    bw = new BufferedWriter(new FileWriter(file));
                    bw.write(text, 0, text.length());
                } finally {
                    if (bw != null) {
                        try { bw.close(); } catch (IOException ioe) { /* ignore */ }
            }//else: input unavailable
        }//createTableBean()

  • How can I implement data type map?

    The getString() method of java.sql.ResultSet interface is not efficient enough.
    I want to map any data type to VARCHAR type,then use the getBytes() method to get the value.
    How can I implement it.
    I know proc can implement it, simply set selda->T[sli] with 1 for any field.

    Hello,
    What's your LabVIEW version ? Do you have a simple example program which demonstrates this behavior ?
    I found another discussions related to your issues with Xcontrols:
    updating type defs in Xcontrol Facade
    No Data Change event generated for a XControl in a Type Def
    XControl facede.vi 
    Hope this helps.
    Regards, 
    Steve M.
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Vidéo-t'chats de l'été : présentations techniques et ingénieurs pour répondre à vos questions

  • Poblem with java.sql.Date while inserting to a table

    Hi All,
    I have a PostgreSQL database table which contains fields(columns ) of type date. I want to insert values to the table in the[b] �dd-MMM-YYYY� format using the prepared statement.
    My code is as follows
    java.text.DateFormat dateFormatter =new java.text.SimpleDateFormat("dd-MMM-yyyy");
    String formatedDate=dateFormatter.format(theDate);
    currentDate = new java.sql.Date(dateFormatter.parse(formatedDate).getTime())
    �������������������
    �������������������
    �������������������
    pst.setDate(12,currentDate);The problem is the currentDate variable gives date only in the �YYYY-MMM-dd� format but requirement is the currentDate variable should give date in the �dd-MMM-YYYY� format and this should be save to table as java.sql.Date type
    There is any solution???? please help me...
    Thanks and Regards,
    Hyson_05

    Hi,
    What are you talking about? A Date does always wrap a millisecond value, and doesn't have any formatting. It's the database, or your program which formats the date that you see.
    In short. You should format the value when you print it, and not when you store it.
    Kaj

  • How to convert JAVA.SQL.DATE date in YYYY/MM/DD format into DD/MM/YYYY

    i am using informix database which accepts date value in the form of DATE format......
    the other part of my application takes date from the field in DD/MM/YYYY format...so i have to convert my java.sql.date in YYYY/MM/DD fromat into DD/MM/YYYY fromat of same type before inserting into db......
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........

    816399 wrote:
    i am using informix database which accepts date value in the form of DATE format......Huh?
    Maybe you mean Informix (fronted by JDBC) expects date values as java.sql.Date objects?
    the other part of my application takes date from the field in DD/MM/YYYY format...
    so i have to convert my java.sql.date in YYYY/MM/DD format into DD/MM/YYYY format of same type before inserting into db......I am not sure why you are talking about formats here.
    There is no formatting inherent in a java.util.Date object
    nor in a java.sql.Date object.
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........You can easily create a java.sql.Date object from a java.util.Date object.
    String s = "31/12/2010";
    java.util.Date ud = new java.text.SimpleDateFormat("dd/MM/yyyy").parse(s);
    java.sql.Date sd = new java.sql.Date(ud.getTime());
    ud = sd; // java.sql.Date extends java.util.Date so no conversion is needed

  • Store a uploaded file of type binary into a java.sql.Blob

    Hi all,
    I try a File-Upload and store the file in a  java.sql.Blob of a MaxDB.
    My Problem is, that I'm not able to import a Model-Attribute of data type byte[]. Further I don't no how to convert the uploaded value attribute of data type binary, in a java.sql.Blob.
    Regards,
    Silvia Hofmann

    http://www.excelsior-usa.com/jet.html
    http://www.ej-technologies.com/products/exe4j/overview.html
    http://jsmooth.sourceforge.net/
    Distributing your Application as an executable JAR file
    Google is your friend.

Maybe you are looking for

  • Inspiron 9300 cd drive performance

    well, i put arch linux on my laptop last week. its one with ide drives, not sata. dell never officially doc'd a difference between the two and put out very few with sata in them. i worked for them so i had the inside info on that, lol. anyway, basica

  • 1Ghz TiBook - Random freezing. Logic board fault?

    Hi all, perhaps one of you might be able to help troubleshoot this, because it's seriously driving me up the wall! I bought a used 1Ghz Titanium (DVI) recently and I'm finding that it freezes randomly when in use, requiring a comand+control restart.

  • SE/30 with 6.0.8 and Farallon PhoneNET Card

    Hello, I have a SE/30 with System 7.5.5 running a Farallon PhoneNET ethernet card and it works fine on th home network. I purchased the Mac on Ebay and it already had the system installed on it. I recently added an external drive and added a partitio

  • KT3 Ultra2-R no boot/no beep D-Bracket 1&2 Red

    I assembled a system with a KT3 Ultra2-R and an AMD XP 2100+ with 300W CodeGen-PSU. The system ran well for 4 weeks without any crashes. Because i had the noisy AMD-boxed CPU-cooler, i installed a very silent noiseblocker-CPU-cooler. The first power-

  • CFCONTENT pdf error

    Hi I recieve an error when I open the pdf generated in CF using the following code... <cfcontent type="application/pdf"> <cfheader name="Content-Disposition" value="filename=test.pdf"> 123 The error i recieve in Acrobat Reader reads as follows: "Adob