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

Similar Messages

  • 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 ?

  • 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.??????

    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.

  • 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.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.

  • 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

  • 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.

  • 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.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.

  • *URGENT HELP REQUIRED* java.sql.SQLException: Invalid Oracle URL specifed

    Hi all,
    In the middle of the last week for my final year project and having to convert to an Oracle database due to compatibility problems with university Tomcat Server and MS Access. I'm having trouble connecting to the Oracle database and would appreciate some help please.
    Running on Windows 98 in the lab here, and the Oracle 9i, release 9.2.0.2.0, J2SDK1.4.0, Classes12.zip installed OK.
    Code for connection looks like this inside the constructor of my class:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    cardSaleConnexion = DriverManager.getConnection("jdbc:oracle:[email protected]:1521:sid","user_name","pwdt");
    System.out.println("Connection Successful ");
    And I'm getting the following error when calling the constructor in a driver program:
    java.sql.SQLException: Invalid Oracle URL specified
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
         at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:188)
         at java.sql.DriverManager.getConnection(DriverManager.java:512)
         at java.sql.DriverManager.getConnection(DriverManager.java:171)
         at CardSale.<init>(CardSale.java:30)
         at Driver.main(Driver.java:11)
    Exception in thread "main"
    Please reply on a very urgent basis.
    Kind regards,
    Peter

    Try ojdbc14.jar as the JDBC driver instead of classes12.zip.
    Refer:
    http://otn.oracle.com/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html
    http://docs.sun.com/source/817-5603-10/index.html
    Database Driver
    This section describes the known database driver issues and associated solutions.
    ID      Summary
    4700531      On Solaris, an ORACLE JDBC driver error occurs.
         This new Java Database Connectivity (JDBC) driver is for Oracle (R) working with JDK1.4. The problem is caused by a combination of the Oracle 9.1 database and ojdbc14.jar. Applying the patch will fix the problem on Solaris 32-bit machine, running an Oracle 9.0.1.3 database.
         Solution
         Obtain and apply the patch to your server from the Oracle Web site for Bug 2199718. Perform the following steps:
         1.��Go to the Oracle web site.
         2.��Click the 'patches' button.
         3.��Type 2199718 in the patch number field.
         4.��Click the 32-bit Solaris OS patch.Go to Metalink.oracle.com.
         5.��Click patches.
         6.��Under patch number, enter 2199718.
         7.��Click the 32 bit Solaris OS patch.
    4707531      On Solaris, accessing an Oracle 9.1 database with an Oracle 9.2 Client may cause data corruption.
         If you use an Oracle (R) 9.2 client to access an Oracle 9.1 database, data corruption might occur when a number column follows a timestamp column.
         The problem might be caused by using the ojdbc14.jar file with an Oracle 9.1 database. Applying the patch might assist in addressing the situation on Solaris 32-bit machines, running an Oracle 9.1 database. This JDBC driver is for Oracle working with JDK1.4.
         Solution
         Obtain the patch that Oracle might make available from the Oracle web site for Bug 2199718 and apply it to your server.
    Regards,
    Pankaj D.

  • Help with Java.Sql package download

    I am compiling some java files with the following :
    import java.sql.*
    and getting errors. I realize I need the java.sql package. Can anyone help me by pointing out where I can download the package?
    Thanks.
    Murthy Gandikota

    This package comes with the JDK. what are your specific problems.

  • Help with:   java.sql.SQLIntegrityConstraintViolationException

    Hi, guys
    I need help with the following exception: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL090403155751200' defined on 'BOOK_ORDER'.
    the things is my primary key is unique, so i checked the indexes and i found that i have two 'SQL090403155751200' indexes.
    I would like to know:
    1. can i delete the index without causing further database problems
    2. what causes this problem and how can i avoid it.
    By the way im using netbeans 6.5 and derby database

    rizza_99 wrote:
    I would like to know:
    1. can i delete the index without causing further database problems
    2. what causes this problem and how can i avoid it.
    By understanding what the application/system is supposed to be doing and the correctly creating indexes on the database that reflect the business needs.
    Once you do that then the nature of the indexes that are needed are obvious.
    You certainly don't delete indexes without that understanding however.

  • Help with java (2 simple classes)

    would anyone be able to help me with some questions about two very short java classes?
    i have come up with some answers of my own, but yeah, i'm not sure how correct my answers are....
    the 4 questions are:
    1. The data attributes m, n and grid in the HeatGrid class are declared private, and methods
    such as gridHeight(), gridWidth() and copyGrid() are provided to extract their value. Why
    is the better class design than simply declaring those attributes as public?
    My answer: So other classes accessing them cannot modify those data atributes, i am not sure why this is better class design.
    2. Why must the (global) constants in HeatSim.java be declared static ?
    My Answer: because HeatSim is what you run first and so you don't create a HeatSim object, you just access its methods, thus the need to make them static.
    3. Assuming HeatGrid has been fully implemented, during the execution of the statement
    HeatGrid = new HeatGrid(inGridFile), how many objects of HeatGrid, double [][] and
    Scanner are created?
    My Answer: 1 HeatGrid object, 1 doulbe[][] object and 1 scanner object
    Which of these objects must still exist after the statement completes execution?
    4. For each of the classes HeatSim and HeatGrid, identify the client and supplier classes
    (including library classes).
    My Answer: So far this is what i have done. for the HeatSim class, i said that the supplier classea are:
    double
    int
    boolean
    String
    Math Class
    viewgrid class
    array
    and the clients for the HeatSim class are:
    HeatGrid class
    if anyone can help me i will but up the VERY short code to these two classes. I am really stuck and any help woould be greatly appriciated! :)
    Lots o love
    Sarah

    ok here is the code (i don't have my compelted copy on me but this will do for the moment).....
    import java.lang.Integer;
    import java.lang.Double;
    import java.text.DecimalFormat;
    public class HeatSim {
        final static boolean ENABLE_VIEW = true; // if true, create GUI to view grid
        final static double DEFAULT_THR = 1.0e-02;
        final static int DEFAULT_PAUSE = 100; // pause between each update of window in ms
        final static int DISPLAY_WIDTH = 7;   // width to print each grid value
        final static int MAX_MN_DISPLAY = 10; // maximum grid size to be displayed
        public static void main(String[] args) {
            // initialize program `parameters' according to the command line,
            // entering `default' values if none were given
            String inGridFile = (args.length < 1)? "": args[0];
            int nIter = (args.length < 2)? 1: Integer.parseInt(args[1]);
            double Thr = (args.length < 3)? DEFAULT_THR: Double.parseDouble(args[2]);
            String dumpFile = (args.length < 4)? "": args[3];
         DecimalFormat residFormat = new DecimalFormat("0.00E0");
            ViewGrid view = null;
            System.out.println("HeatFlow simulation program");
            if (inGridFile.equals("")) {
                System.out.println("Error: an empty grid file name was entered");
                return;
            // create HeatGrid object
            HeatGrid heatGrid = new HeatGrid(inGridFile);
            int m = heatGrid.gridHeight();
            int n = heatGrid.gridWidth();
            if (m <= MAX_MN_DISPLAY  && n <= MAX_MN_DISPLAY) {
                System.out.println("\nGrid at time 0:" );
                heatGrid.display(DISPLAY_WIDTH);
            if (ENABLE_VIEW) {
                // create a ViewGrid WINDOW object to view the grid
                view = new ViewGrid(m+2, n+2, DEFAULT_PAUSE);
                view.display(heatGrid.time(), 0.0, heatGrid.copyGrid());
            while (heatGrid.time() != nIter && heatGrid.residual() > Thr) {
                heatGrid.iterate();
                if (m <= MAX_MN_DISPLAY  && n <= MAX_MN_DISPLAY) {
                    System.out.println("Grid at time " + heatGrid.time() +
                                    " has residual " +
                         residFormat.format(heatGrid.residual()));
                    heatGrid.display(DISPLAY_WIDTH);
                if (ENABLE_VIEW) {
                     view.display(heatGrid.time(), heatGrid.residual(),
                                  heatGrid.copyGrid());
            } //while(...)
            if (ENABLE_VIEW) {
                view.finalize();
            if (!dumpFile.equals("")) {
             heatGrid.dumpGrid(dumpFile);
            System.out.println("\nHeat Flow simulation of (" + m + "+2)x(" + n +
                               "+2) grid ends at time " +  heatGrid.time() +
                               " with residual " +
                      residFormat.format(heatGrid.residual()));
        } //mainProgram()
    } //HeatSim
    import java.util.Scanner;
    import java.io.*;
    import java.text.DecimalFormat;
    public class HeatGrid {
        private int m, n;
        private double[][] grid;     // m+2 x n+2 array representing a grid
        private int t;               // the time the grid has been evolved
        private double resid;        // residual left from the last timestep
        // initializes m, n and grid according to the information in the grid file
        // of name gridFileN; sets t to 0, and resid to Double.MAX_VALUE
        public HeatGrid(String gridFileN) {
        } //HeatGrid()
        // returns the value of m
        public int gridHeight() {
            return 0;         // [ replace with an appropriate value ]
        } //gridHeight()
        // returns the value of n
        public int gridWidth() {
            return 0;         // [ replace with an appropriate value ] =
        } //gridWidth()
        // returns the value of t
        public int time() {
            return 0;         // [ replace with an appropriate value ]
        } //time()
        // returns the value of the residual from the previous timestep
        public double residual() {
            return 0;         // [ replace with an appropriate value ]
        } //residual()
        // returns a copy of the grid
        public double[][] copyGrid() {
            return null;         // [ replace with an appropriate value ]
        } //copyGrid
        // precondition: all elements of grid can be printed to 1 decimal place
        // using width characters.
        // prints the m+2 x n+2 grid by rows, rows in descending order.
        // All values are printed to 1 decimal place, and are right-justified
        // in a text field of width characters.
        // Note: this method is for debugging; hence right-justification is useful
        public void display(int width) {
        } //display()
        // advance the simulation a single timestep
        public void iterate() {
         } //iterate()
        // prints the m+2 x n+2 grid by rows, rows in ascending order.
        // All values are printed to 2 decimal places, with at least one space
        // between them.
        // Note: this method is intended for result checking by a computer program;
        // thus justification is not important.
        public void dumpGrid(String outGridFileN) {
        } //dumpGrid

  • 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()

Maybe you are looking for

  • Contacts getting mixed up by BB

    Hi For some reason out of the blue my contacts get mixed up by my BlackBerry q10 Eg. "Peter Miller"s details are suddenly (inconsistently) merged with "John Smith". Both are saved contacts. This keeps happening without my touching the phone. I can ge

  • How to Insert a Status Bar to my application

    Hello all I use JBuilder v9 and would like to add a status bar at the bottom of the main frame in my program. I checked the manual pages but there is no such class as StatusBar or JStatusBar. When I type StatusBar (or JStatusBar) sb = new StatusBar (

  • How do I get a song to download properly? Downlaoded an album but one song only plays first 2 seconds.

    Can only listen to the first 2 seconds of a song, checked for downloads incomplete and get all songs downloaded message, also have latest iTunes version. Tried restarting my PC but did not help. How do I get all of the song re-downloaded properly?

  • Image of Flash Drive

    I want to store a copy of the contents of my flash drive (32Gb work back-up) on my Mac but dont want all the photos and files etc added to my list of documents and photos on my Macbook pro. How do I do this? I suppose I just want and image on my desk

  • GR Processing time using MRP areas

    Hi Experts, I have setup where the same materials is purhcased but planned indemendent using MRP areas. There is a requirement to maintain a different GR Processing time to the material depending on the MRP area. I am only able to maintain the GR pro