Name of an int ( e.g. java.sql.Types )

I have the sql.Types code as an int number and want to display the name. Is there a straightforward method or do I have to search it in a loop like here ?
String getName(int i) {
for (Field f: java.sql.Types.class.getFields()) {
     if (f.getType().equals(int.class)) {
          if (f.getInt(f.getType()) == i) {
          System.out.println( i + " = "+f.getName() );
          // e.g.               8 = DOUBLE
          return f.getName();
}This question is not specific to java.sql.Types I guess (that's why I post here).
A dedicated hint for sql is appreciated as well, however ;)

Seems the loop is required and it works (in no time, there aren't too many Fields)
     if (f.getInt(f.getType()) == i) {Having a closer look, I do not understand the inner f.getType() , however.
f.getInt() requires an object, but anything, including null, works ?!
Any hint, or link where to learn about java.lang.reflect.Field, please ?

Similar Messages

  • Create table dinamically using java sql types?

    Hi! I've an application that reads an XML file. This file contains de definitions of some tables, using java sql types. For example:
    <dbtable>
      <dbtablename>Name of table</dbtablename>
      <dbtablefield>
        <name>Name of table field</name>
        <type>java.sql.Types.VARCHAR</type>
        <length>10</lenght>
        <canNull>0</canNull>
        <isPK>1</isPK>
      </dbtablefield>
    </dbtable>That's a little example of one table, with one field. Is a java.sql.Types.VARCHAR (or is equivalent in int), which has a size of 10, it cannot be null and is a primary key for the table.
    Now, the lenght, null, and primary keys are not problem at all. What I want to know, is how do I create de table using the java.sql.Types. I mean, I don't want to hard code:
    String s = "CREATE TABLE name (COLUMN VARCHAR(10)...";Instead, I want to use some "wild cards", as are used in PreparedStatement. The idea of this is that no matter what DB I'm using, I must always be capable of creating the tables not worrying for the DB. I mean, I must be able to create the table in Oracle, SQL Server, DB2, etc., using the same XML and the same java class.
    Something like:
    String s = "CREATE TABLE name (COLUMN ? (10)...";
    someobject.setObject(1,java.sql.Types.VARCHAR);
    someobject.execute(); //create tableIs this possible? Or do I have to make a map for each DB?
    Thanks a lot for your help! Dukes available!

    you can provide some fields at runtime..
    for example
    "CREATE TABLE name (COLUMN" + arg[1] +"(10)..."
    here arg is the string array passed into the main.

  • Java.sql.Types.RAW

    I know you can map a LONG RAW sql type to the java class oracle.sql.RAW when wrapping the java code in your pl/sql wrapper. The problem I am having is that within my java code I am returning result set and using reslutSetMetaData to determine if the column is a varchar or clob with a switch statment and a case comparison using java.sql.Types.whatever sql type i am looking for. I am running into a problem when trying to write a case statement for long raw columns. What would be the statement to use for this. Below is an example of the code.
    int type = rsmd.getColumnType(1);
    switch (type) {
    case java.sql.Types.CLOB:
    code to execute when CLOB type
    break;
    case java.sql.Types.Raw:
    code to execute when LONG RAW type
    break;
    Thanks in advance,
    Kevin
    null

    user1330140 wrote:
    ...the return type which is defined inside DBMS_XDB_VERSION package
    I think there are some threads somewhere that points to Oracle documentation somewhere that says that is not possible with JDBC.
    I could certainly be mistaken however.
    If I am not mistaken then you would need to
    1. Wrap the call to that in another proc.
    2. That proc extracts the result into something that is visible in the jdbc driver.

  • Java.sql.Types.CLOB not returned

    When I run the following on an oracle 8.1.7 server using thin/OCI driver on a table with a CLOB column,
    DatabaseMetaData dbmd = conn.getMetaData();
    ResultSet rs = dbmd.getColumns( null, null, tableName, "%" );
    while (rs.next()){
    int colType = (int)rs.getShort(5);
    I dont get java.sql.Types.CLOB returned in colType, instead I get java.sql.Types.OTHER.
    However, after a query on the same table, the result set metadata.getColumnType() returns java.sql.Types.CLOB.
    Any ideas?
    Thanks in advance

    You can't do that. You can't do it in SQL either: there's no way to call a stored procedure without providing parameters of a specific type.
    There are two things you can do, however: one is to declare the parameter as VARCHAR and hope it's not a BLOB or something that the db will not automatically convert to VARCHAR and the other is to do a SELECT in the procedure you are calling instead of returning the value as an output parameter. The second option is better in that you can then use ResultSet.getObject() from Java and obtain the correct object type, not a String you might need to parse afterwards.
    Alin.

  • If DB Column java.sql.Types=CHAR = Workshop autogen EJB CMP Filed=Boolean

    Hi everybody<br>
    <p class="MsoNormal"><span lang="EN-US">When a user automatically
    creates/generates an Entity Bean via BEA Workshop EJB Project option: ‘<b>new
    Entity bean from database table</b>’ and DB Table Column is of type <b>CHAR</b>,
    Workshop creates a <b>@ejbgen:cmp-field</b> of Java type <b>Boolean</b>, NOT of
    <b>Character</b>!</span></p>
    <p class="MsoNormal"><span lang="EN-US">I completely agree that the developer
    must be acquainted with the Data Base and DB Tables as well and he can manually
    correct </span><span lang="EN-US" style="font-size: 10.0pt">SET & GET</span><span lang="EN-US">
    Boolean to Character in EJB source code view or he’ll receive an error if he
    tries to <b>set<i>FieldName</i></b><i>(String/Character) </i>in <b>ejb</b>
    methods.</span></p>
    <p class="MsoNormal"><span lang="EN-US">But suppose that a developer has
    urgently received an order to build an EJB Project for a thousand of DB Tables
    and he hasn’t been acquainted with all of them. He has created the EJBs via <b>
    ‘new -> Entity bean from database table’. </b>He has created some EJB Finders,
    for example a finder:  <b>ejbgen:finder Collection find<i>All</i>()</b>.
    (<i>Suppose he hasn’t used <b>group-name</b> finder property</i>)</span></p>
    <p class="MsoNormal"><span lang="EN-US">He has invoked <b>find<i>All</i>()</b>
    method and depends on the JDBC Driver used, he will receive an </span>
    <span lang="EN-US" style="font-size: 10.0pt">ERROR</span><span lang="EN-US">,
    printed within the Server start console <b>at least</b> OR the result after <b>
    get<i>FieldName</i></b>() will be '<b>false</b>', not an expected <i><b>char</b></i>
    symbol.</span></p>
    <p class="MsoNormal"><b><span lang="EN-US">Anxious conclusion: </span></b></p>
    <p class="MsoNormal"><span lang="EN-US">If<b>  </b>DB Column<b>  java.sql.Types
    = </b></span><span lang="EN-US" style="font-size: 10.0pt"><b>CHAR</b>    </span><span lang="EN-US">then</span><span lang="EN-US" style="font-size: 10.0pt">  
    </span><span lang="EN-US"><b>getJavaObjectType = Boolean </b> then corresponding
    EJB CMP Filed  will always be   <b>Boolean</b>  in BEA Workshop !</span></p>
    <p class="MsoNormal"><i><span lang="EN-US">Following description considers the
    </span><span lang="EN-US" style="font-size: 11.0pt">PROBLEM</span><span lang="EN-US">:</span></i></p>
    <p class="MsoNormal"><span lang="EN-US">Class<b>
    weblogic.jdbc.utils.schema.Column </b>from<b> weblogic.jar </b>and its method<b>
    String getJavaType() </b>has a <b>switch(getType())</b> with <b>case:</b></span></p>
    <p class="MsoNormal"><span lang="en-us"><b> if(this.getSize() == 1)<br>
        return "boolean"; <br>
    else<br>
        return "String";</b></span></p>
    <p class="MsoNormal"><span lang="en-us">and </span>
    <span lang="EN-US" style="font-size: 12.0pt; font-family: Times New Roman">
    another </span><span lang="en-us"> method <b>String getJavaObjectType() </b>
    {</span></p>
    <p class="MsoNormal"><b><span lang="en-us">String s = this.getJavaType();</span></b></p>
    <p class="MsoNormal"><b><span lang="en-us">...</span></b></p>
    <p class="MsoNormal"><b><span lang="en-us">    
    if(s.equals("boolean"))<br>
            return "Boolean";</span></b></p>
    <p class="MsoNormal"><span lang="en-us"><b>    
    if(s.equals("char"))<br>
            return "Character";</b></span></p>
    <p class="MsoNormal"><span lang="en-us"><b>... }<br>
    </b>but according to </span><span lang="EN-US"><b>switch(getType())</b> which
    has NOT  a<b> 'case' return char</b>, </span><span lang="en-us"><b>
    'Character' </b>will never be returned, so:</span></p>
    <p class="MsoNormal"><span lang="EN-US"><b>@ejbgen:cmp-field</b> of Java type <b>
    Character </b></span><span lang="en-us">will never be generated by Workshop.</span></p>
    <p class="MsoNormal" align="left"><span lang="EN-US">More often than not  I’ve
    ran into this little but disturbing problem, so I’ve corrected <b>
    weblogic.jdbc.utils.schema.Column.getJavaType switch case </b>as:</span></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">…</span></b></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">       
    case 1:     // '\001'  //</span><span lang="EN-US" style="font-size: 10.0pt">CHAR</span></b></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">
                if(this.getSize() == 1)</span></b></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">          
         return "char";  </span></b></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">…</span></b></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">private
    static final boolean </span><span lang="EN-US" style="font-size: 10.0pt">
    CHAR_TO_BOOLEAN</span><span lang="EN-US"> = false;     </span></b><span lang="EN-US">//as
    a field variable</span></p>
    <p class="MsoNormal" style="text-indent:35.4pt"><b><span lang="EN-US">…</span></b></p>
    <p class="MsoNormal" style="text-indent:35.4pt"> </p>
    <p class="MsoNormal" style="text-align:justify"><span lang="EN-US">Using this
    correction and precompiled class I’ve built and tested a lot of projects w/o
    problems so far.</span></p>
    <p>Best regards: George Moykin<p>
    P.S. I appologize to site Admins for posting the same topic in EJB forum, but it refers to EJBs too.

    Hi,<br>
    In your database, we have some columns of CHAR type and this is the decision of our DB architects. I understand the case ‘male’ or ‘female’, true or false, either; but only if I must choose between 2 variants. Our DB columns contain char symbols such as ‘:’, ‘;’,’-’ etc. and for some inner purposes our architects decided DB columns to be of type CHAR, not VARCHAR. In this case, the Workshop transformation ‘CHAR to BOOLEAN’ doesn’t do useful work. So, I’ve decided to modify some weblogic.jar classes (as described) and now I’m able to generate Entity EJB from DBMS Tables w/o manual intervention.<br>
    Best Regards

  • Help on java.sql.Types class

    Hai Friends ,
    I want some help on java.sql.Types class .
    What is the use of the above class ?
    Some details about this class.

    Good Morning Yekesa
    First of all i would like to thank U for looking into my problem.
    I am using java.sql.Types.OTHER for
    {"?=CALL(storedprocedurename.functionname(?))"}
    registerOutParameter(1,javal.sql.Types.OTHER)
    setString(2,"user")
    here the
    second parameter passes an argument to function name ( viz. username say "user")
    and the function will return the ref cursor as follows:
    // declaration in pl/sql procedure
    begin
    rc ref cursor
    open rc for select * from ss_user where login_name="user";
    return rc;
    end
    now the stored procedure has a return value (i.e. stored function) which it needs to register as
    registerOutParameter(1,javal.sql.Types.OTHER)
    and it finally results in the following errors :
    Loading driver
    Before conn stmt
    After conn stmt
    Calling Stored procedure
    Stored procedure called
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:243)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:2487)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:64)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:54)
    at sptest.<init>(sptest.java:28)
    at sptest.main(sptest.java:49)
    T couldn't understand why it is saying Invalid Column Type because its working fine with both
    java.sql.Types.INTEGER
    and
    java.sql.Types.VARCHAR
    Pl help me at the earliest as i have wasted a lot of time on it.
    pl mail me in detail at [email protected]
    bye then
    bansi
    null

  • Java.sql.types and oracletypes

    There appear to be difference in the way the constants are mapped in java.sql.types vs oracletypes(). For example date is '91' in oracletypes and '93' in java.sql.types. The DatabaseMetaData.getColumns() function reports data_type as a java.sql.type. Is there any mapping available from one to the other.
    Thanks

    Erm,
    One way to find out, I reckon.
    Good Luck,
    Avi.

  • Java.sql.Types.??????

    I know clob columns in an oracle database are java.sql.Types.CLOB. What are long raw columns defined as java.sql.Types.???
    Thanks in advance,
    kmw

    Hi ,
    Long has no correspondng type in Oracle.sql.Types.So u can access it using the getOBject and setObject.Why do u need to defing the long ?Is it for use i the getter and setter methods of ResultSet or Statements.If so , u have to use streaming and so there is really no need to worry abt the type definition as u are defaulting to an AsciiStream.
    Hope it helps.

  • SetNull(2, java.sql.Types.DATE);

    If I use setNull(1, java.sql.Types.DATE); function, it will insert null on my table's column.
    I want to select the date from another table and insert into my table's column, what should I do?
    I am sure I cannot call setNull(1,java.sql.Types.DATE), it will insert NULL in my column.
    Thanks in advance.

    Hi,
    I think you will be better of in asking ths question in Java forum or Oracle Developer forum.
    Regards

  • Java.sql.Types.BOOLEAN in 9i

    I am trying to figure out what data type i need to set on columns in 9i that will represent java.sql.Types.BOOLEAN data. The docs that i have read around the web say to use a "Byte" type but this is not in the list on my server; in MS SQL2000 i use the "Bit" type and it works great.. is there something simlar in Oracle?

    Hi ,
    Long has no correspondng type in Oracle.sql.Types.So u can access it using the getOBject and setObject.Why do u need to defing the long ?Is it for use i the getter and setter methods of ResultSet or Statements.If so , u have to use streaming and so there is really no need to worry abt the type definition as u are defaulting to an AsciiStream.
    Hope it helps.

  • GetScale(int) method of java.sql.ResultSetMetaData

    On weblogic 8.1 instance I am using oracle JDBC TYPE 4 Thin driver.
    The jar file for the driver is ojdbc14.jar.
    Our database is 9.2.0.
    code excerpt:
    //rs is the resultset
    if (rs != null)
    ResultSetMetaData RSMD = rs.getMetaData();
    int i = RSMD.getColumnCount();
    int test=0;
    String cName="";
    for(int j = 1; j <= i; j++)
    test = RSMD.getScale(j);
    cName = RSMD.getColumnName(j);
    System.out.println("The scale of column name : "+cName+ " is " +test);
    The output is:
    The scale of column name : PERSON_ID is -127
    The scale of column name : FIRST_NAME is 0
    The scale of column name : LAST_NAME is 0
    The data type of column PERSON_ID is NUMBER. Why is it so? getScale(int) should return zero for a column whose data type is NUMBER.
    Help me. Is it driver specific probelm?

    Hi,
    I have a similar problem. I want to find out the column names when i fire raw-sql. I use SQLCall to do this.
    Then I get a Vector<DatabaseRow>.
    Vector vDR = session.executeQuery( new SQLCall( "select * from table_name" ) )
    Now Is there a way to find out the column names dynamically. In the javadocs i see that objDatabaseRow.keys() returns an Enum<DatabaseField>... but i cant see javadocs on how to use DatabaseField.
    So is there any other way ?
    Thanks,
    Krishna

  • ODI Agent error: java.sql.SQLException: Invalid column name

    When running a scenairo on a standalone ODI agent, it hangs on "Wait" state. The ODI agent's log is logging the following errors over and over again.
    We are in Fusion Application Development and are using Middleware D8B4A RC5.
    [2011-01-07T14:35:16.381-08:00] [odi] [WARNING] [] [oracle.odi.agent] [tid: 4215] [ecid: 0000IpYbCrKE8TQRyaJ7D01D8^zE00009o,0] /oraclediagent/invoke.do[[
    oracle.odi.core.security.SecurityManager.doODIInternalAuthentication(SecurityManager.java:356)
    oracle.odi.core.security.SecurityManager.createAuthentication(SecurityManager.java:331)
    oracle.odi.runtime.agent.servlet.AgentServlet.doPost(AgentServlet.java:418)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:503)
    org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389)
    org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
    org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    org.mortbay.jetty.Server.handle(Server.java:326)
    org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)
    org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:879)
    org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:749)
    org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:219)
    org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
    org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
    [2011-01-07T14:35:18.341-08:00] [] [ERROR] [ODI-1131] [] [tid: 4214] [ecid: 0000IpYaiZCE8TQRyaJ7D01D8^zE00009n,0] [arg: OracleDiAgent] [arg: java.sql.SQLException: Invalid column name] Agent OracleDiAgent encountered an error: java.sql.SQLException: Invalid column name

    Are you sure the datasources point to the right master/work configuration, and that your repository is correctly up-to-date? This looks like the agent trying to connect a repository, but the repository is not updated correctly, or misses some columns. The whole stack (and the name of the missing column) would help of course.

  • 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 do I return a java.sql.Timestamp data type in a Web service?

    I'm new to workshop and java. I'm creating a mini application to simulate a real work Web Service (development environment is on an intranet). I was able to completely simulate the Web Services minus all date values.
    I'm using a standard weblogic workshop database controls that are feeding the various WebServices and their methods (Web services was generated from DB control). I get a java type not support error when I attempt to return a java.sql.Timestamp. I temporarily got around the problem by omitting all dates from the sql.
    However, we are at the point where we need the complete record.
    My two questions
    1) What java data type do I convert the java.sql.Timestamp to
    2) Where and how do I do it in workshop.
    Thanks in advance
    Derrick
    Source view from workshop looks something like this.
    public interface MyData extends DatabaseControl, com.bea.control.ControlExtension
    static public class dbOverallRec
    public String key;
    public String field1;
    public int field2;
    public java.sql.Timestamp create_date
    public dbOverallRec () {};
    *@jc:sq; rowset-name="OverallRowSet" statement::
    *select key, field1, field2 ,create_date from overall where key={KEY}::
    dbOverallRec getOverallByKey(String Key);
    * I had to omit the create_date to get it to work

    You should try changing java.sql.Timestamp to java.util.Calendar.
    java.util.Calendar maps to the dateTime type in XML Schema, and TIMESTAMP as a JDBC type.
    Regards,
    Mike Wooten

  • Unable to insert dates and blobs with java.sql.PreparedStatement

    I got a problem when i try to insert into a table using Prepared
    statement.
    The table definition is
    TABLE USER_ACCOUNTS
    USER_ACCOUNT NUMBER(12),
    START_DATE DATE,
    END_DATE DATE,
    NB_UNSUCC_LOG_AT NUMBER(2),
    USER_ID VARCHAR2(30),
    CREATION_DATE DATE;
    In my java classes if i do the following code everithing's fine:
    connection = pool.getConnection();
    connection.executeUpdate("
    INSERT INTO USER_ACCOUNTS(
    USER_ACCOUNT,
    START_DATE,
    END_DATE,
    NB_UNSUCC_LOG_AT,
    USER_ID,
    CREATION_DATE)
    VALUES(
    123,
    TO_DATE('2001-11-20','YYYY-MM-DD'),
    NULL,
    0,
    'TOTO',
    TO_DATE('2001-11-20','YYYY-MM-DD')
    but when i do the following, it gives me errors and no rows are
    created! what am i doing wrong?
    connection = pool.getConnection();
    pstmt = connection.prepareStatement(
    "INSERT INTO USER_ACCOUNTS(
    USER_ACCOUNT,
    START_DATE,
    END_DATE,
    NB_UNSUCC_LOG_AT,
    USER_ID,
    CREATION_DATE)
    VALUES(?,?,?,?,?,?)");
    int userAccount = 123;
    java.sql.Date creationDate = new Date(123445566);
    java.sql.Date startDate = new Date(123445566);
    java.sql.Date endDate = null;
    int nbUnsuccessfullLogonAttempt = 0;
    String userid ="TOTO";
    pstmt.setInt(1, userAccount);
    pstmt.setDate(2, startDate);
    pstmt.setDate(3, endDate);
    pstmt.setInt(4, nbUnsuccessfullLogonAttempt);
    pstmt.setString(5, userid);
    pstmt.setDate(6, startDate);
    pstmt.executeUpdate();
    ____________ at this point i receive an SQL Exception that said
    invalid delimiter in string
    i also tried with VALUES
    (?,TO_DATE('?', 'YYYY-MM-DD'),?,?,?,TO_DATE('?', 'YYYY-MM-DD'))
    and the result was invalid month in date
    Thanks for your help!
    Julien De Santis

    > org.hibernate.PropertyValueException: not-null property references a null or transient value: BookOpr.Author.BkBk is null while it should not be, according to the mapping:
    <class name="BookOpr.Author" table="author">
        <many-to-one name="Bk" column="bid" class="BookOpr.Book" not-null="true"/>There are 2 solutions:
    1) Don't null the BookOpr.Author.Bk.
    2) Remove not-null="true" or set it to "false".

Maybe you are looking for