JDBC getString

Hi,
We are experiencing some strange behaviour with the JDBC getString method on Jdeveloper 10g (I'll also post in the JDBC forum).
getString is returning the hex representation of the string when it is executing in the OC4J container, but returns the correct data when it executes in the internal Jdeveloper java machine ie when we run the class without starting the Web App in the oc4j container.
Anyone experienced this?
Thanks,
Tom

if(DC.equals("D"))
System.out.println(DC+i);
else if(DC.equals("C"))
System.out.println(DC+i);

Similar Messages

  • GetString issue

    Hi,
    We are experiencing some strange behaviour with the JDBC getString method on Jdeveloper 10g (I'll also post in the Jdeveloper forum).
    getString is returning the hex representation of the string when it is executing in the OC4J container, but returns the correct data when it executes in the internal Jdeveloper java machine ie when we run the class without startinbg the Web App in the oc4j container.
    Anyone experienced this?
    Thanks,
    Tom

    Thanks for the reply.
    I am still encountering the issue after checking the classpath both in the IDE debugger and the oc4j container via a java call: System.getProperty("java.class.path").
    This returns a classpath that contains:
    C:\Jdev905\j2ee\home\../../jdbc/lib/nls_charset12.jar;
    What is interesting however is that the JDBC doc states:
    The Thin driver obtains language and territory settings (NLS_LANGUAGE and NLS_TERRITORY) from the Java locale in the JVM user.language property.
    When I probe the properties:
    Properties properties = System.getProperties();
    I see a user.language property (set to "en") in the IDE BUT NOT in the oc4j container.
    Is this the cause of the conversion to (or lack of conversion from) hex in the OC4J container?
    By the way my JDBC version is 9.0.1.4.0 using:
    DatabaseMetaData meta = con.getMetaData();
    System.out.println("JDBC driver version is " + meta.getDriverVersion());
    .. and I'm running on Windows 2000.
    Any help is appreciated!
    Tom

  • How does Oracle JDBC thin driver handle numbers via getString?

    Hi,
    I have a query regarding how numbers are handled by the oracle jdbc thin driver. The issue I am facing is with regards to the decimal separator (. is en_US and , in pt_BR)
    e.g. Consider the below code,
    Connection conn = DriverManager.getConnection(...);
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select value from test_table1");
    while (rset.next())
    System.out.println (rset.getString(1));
    test_table1 has a single column of sql type 'number' with a single row having value "123.45"
    NLS_NUMERIC_CHARACTERS = ".,"
    Database version = 10.2.0.2.0
    There is a (generic) method to which a ResultSet is passed and it returns a dictionary of key value pairs. All column values from the ResultSet are retrieved using getString method of ResultSet.
    My question is whether the jdbc driver formats numbers (based on the locale) before returning it as a string as part of the getString method?
    e.g.
    java -Duser.language=pt -Duser.region=BR TestJDBC
    prints "123.45" and not "124,45"
    Is there a reason why getString always retrieves a number column value with '.' as the decimal separator?
    To help make things a bit more clear, all the column values retrieved are then converted into an XML (and hence the conversion to string)
    At present, the only way I see out of this is to handle numbers differently.
    i.e. something similar to,
    if (resultsetmetadata.getcolumntype .. = double OR float OR int OR long.. )
    NumberFormat.getInstance().format(rset.getDouble(1));
    Is there a better way to resolve this issue?
    Thanks,
    Binoy

    user565580,
    As has been already stated, Oracle does not have data-types INTEGER or SMALLINT, only NUMBER.
    So even though Oracle lets you write INTEGER, it really creates a NUMBER.
    (As Joe mentioned.)
    Other databases don't have a NUMBER data-type, they have INTEGER, SMALLINT, etc.
    Originally, Oracle database only had three data-types:
    CHAR
    DATE
    NUMBER
    If you're going to be working with Oracle database, then you need to adapt yourself to its limitations.
    So you'll probably need to define NUMBER data-types using scale and precision.
    (As Kuassi mentioned.)
    Good Luck,
    Avi.

  • GetString and JDBC

    Does anybody know how to turn off converting national characters (between character code on database server and local character codes represented in Java program) while they are reading from Oracle database (or any other) via getString method (of ResultSet class)? I want this because sometimes I get '?' instead of national character.
    Or mayby is there any other method to get this trouble codes?

    I assume you have set the charecter encoding corectly for you JVM. If you have then try and set the encoding on the oracle database also. for example, if the charecter encoding on the JVM and that of varchar in the database is set to the same (say UTF-8), I think it should work without problems.
    if you want to convert a String into bytes according to the specified character encoding try the method
    public byte[] getBytes(String enc)
    in the class java.lang.String
    hope this is helpful,
    regards

  • Oracle JDBC: using getString() vs getRAW() and setString() vs setRAW()  for RAW colum

    When extracting a column from an OracleResultSet that has type RAW(16) in the
    database or when binding a parameter for the RAW database column, is there any
    pitfalls with using getString() / setString() methods as opposed to getRAW() /
    setRAW() ? (for example, character-set-related ones).
    We need to pass the values in the RAW columns through URLs and have to convert
    them to Strings before doing this. However, stringValue() method of the RAW
    object creates a string that we could not easily restore to the "same" RAW
    object (the only way that we found was to use the HEXTORAW() method in all
    queries where that RAW value needed to be bound). Some folks however just treat
    RAW values as Strings in their Java code (with getString/setString methods), and
    so we were wondering if this is acceptable or there are any problems with this
    simpler approach. If it IS acceptable, why would anyone use RAW Java objects at
    all?
    Thanks,
    Menon:)

    When extracting a column from an OracleResultSet that has type RAW(16) in the
    database or when binding a parameter for the RAW database column, is there any
    pitfalls with using getString() / setString() methods as opposed to getRAW() /
    setRAW() ? (for example, character-set-related ones).
    We need to pass the values in the RAW columns through URLs and have to convert
    them to Strings before doing this. However, stringValue() method of the RAW
    object creates a string that we could not easily restore to the "same" RAW
    object (the only way that we found was to use the HEXTORAW() method in all
    queries where that RAW value needed to be bound). Some folks however just treat
    RAW values as Strings in their Java code (with getString/setString methods), and
    so we were wondering if this is acceptable or there are any problems with this
    simpler approach. If it IS acceptable, why would anyone use RAW Java objects at
    all?
    Thanks,
    Menon:)

  • Query works in Oracle Client but not JDBC

    The query is as follows:
    SELECT COUNT(*) THE_COUNT FROM sentorders WHERE ordersentdate BETWEEN '15-JAN-01' and '15-JAN-03';When I run this query in the Oracle client (SQL+) it tells me that THE_COUNT is 4 which is correct but when I use the following JDBC code I get THE_COUNT is 0 which is incorrect.
    public ResultSet viewTotalSentOrdersByDate()
      throws SQLException, Exception {
          String beginDate = "15-JAN-01";
          String endDate = "15-JAN-03";
          ResultSet rs = null;
        try  {
          String queryString = ("SELECT COUNT(*) THE_COUNT FROM sentorders WHERE ordersentdate BETWEEN '" + beginDate + "' and '" + endDate + "'");
          System.out.println(queryString);
          Statement stmt = con.createStatement();
          rs = stmt.executeQuery(queryString);
          while(rs.next()) {
           System.out.println(rs.getString("THE_COUNT"))
        } catch (SQLException sqle) {
          error = "SQLException: Could not execute the query.";
          throw new SQLException(error);
        } catch (Exception e) {
          error = "An exception occured.";
          throw new Exception(error);               
        return rs;
      }Thanks for the help
    Zac

    The query is as follows:
    SELECT COUNT(*) THE_COUNT FROM sentorders WHERE ordersentdate BETWEEN '15-JAN-01' and '15-JAN-03';When I run this query in the Oracle client (SQL+) it tells me that THE_COUNT is 4 which is correct but when I use the following JDBC code I get THE_COUNT is 0 which is incorrect.
    public ResultSet viewTotalSentOrdersByDate()
    throws SQLException, Exception {
    String beginDate = "15-JAN-01";
    String endDate = "15-JAN-03";
    ResultSet rs = null;
    try {
    String queryString = ("SELECT COUNT(*) THE_COUNT FROM sentorders WHERE ordersentdate BETWEEN '" + beginDate + "' and '" + endDate + "'");
    System.out.println(queryString);
    Statement stmt = con.createStatement();
    rs = stmt.executeQuery(queryString);
    while(rs.next()) {
    System.out.println(rs.getString("THE_COUNT"))
    } catch (SQLException sqle) {
    error = "SQLException: Could not execute the query.";
    throw new SQLException(error);
    } catch (Exception e) {
    error = "An exception occured.";
    throw new Exception(error);
    return rs;
    }Thanks for the help
    Zac

  • Using JDBC to write a DAT file with delimiters to a database

    Hi Everybody
    I am new to JDBC and i am trying out some small applications: I downloaded this small program and tried to compile it and and I got the following errors: ( I have MySql installed). I have to set the classpath for the driver. But I am not sure why I am gettting the NullPointerException though)
    I will be very gratefull to your help. Thanks a lot..
    Loading JDBC Driver -> oracle.jdbc.driver.OracleDriver
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at us.ilango.WriteFileToTable.<init>(WriteFileToTable.java:69)
         at us.ilango.WriteFileToTable.main(WriteFileToTable.java:367)
    java.lang.NullPointerException
         at us.ilango.WriteFileToTable.createTable(WriteFileToTable.java:97)
         at us.ilango.WriteFileToTable.main(WriteFileToTable.java:368)
    Exception in thread "main"
    the Program is as follows:
    package us.ilango;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.StringTokenizer;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.text.NumberFormat;
    import java.text.ParseException;
    * The following class provides an example of how to read a simple text file
    * of records and then insert them into a table in a database. A text file
    * named Employee.txt will contain employee records to be inserted into the
    * following table:
    *      SQL> desc emp
    *      Name              Null?    Type
    *      EMP_ID              NOT NULL NUMBER
    *      DEPT_ID                      NUMBER
    *      NAME                NOT NULL VARCHAR2(30)
    *      DATE_OF_BIRTH       NOT NULL DATE
    *      DATE_OF_HIRE        NOT NULL DATE
    *      MONTHLY_SALARY      NOT NULL NUMBER(15,2)
    *      POSITION            NOT NULL VARCHAR2(100)
    *      EXTENSION                    NUMBER
    *      OFFICE_LOCATION              VARCHAR2(100)
    * NOTE: This example will provide and call a method that creates the EMP
    *       table. The name of the method is called createTable() and is called
    *       from the main() method.
    public class WriteFileToTable {
        final static String driverClass    = "oracle.jdbc.driver.OracleDriver";
        final static String connectionURL  = "jdbc:oracle:thin:@localhost:1521:CUSTDB";
        final static String userID         = "scott";
        final static String userPassword   = "tiger";
        final static String inputFileName  = "Employee.txt";
        final static String TABLE_NAME     = "EMP";
        final static String DELIM          = ",";
        Connection   con                   = null;
         * Construct a WriteFileToTable object. This constructor will create an
         * Oracle database connection.
        public WriteFileToTable() {
            try {
                System.out.print("  Loading JDBC Driver  -> " + driverClass + "\n");
                Class.forName(driverClass).newInstance();
                System.out.print("  Connecting to        -> " + connectionURL + "\n");
                this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
                System.out.print("  Connected as         -> " + userID + "\n");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
         * Method used to create the initial EMP table. Before attempting to create
         * the table, this method will first try to drop the table.
        public void createTable() {
            Statement stmt = null;
            try {
                stmt = con.createStatement();
                System.out.print("  Dropping Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
                System.out.print("    - Dropped Table...\n");
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                System.out.print("    - Table " + TABLE_NAME + " did not exist.\n");
            try {
                stmt = con.createStatement();
                System.out.print("  Creating Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("CREATE TABLE emp (" +
                                 "    emp_id           NUMBER NOT NULL " +
                                 "  , dept_id          NUMBER " +
                                 "  , name             VARCHAR2(30)  NOT NULL " +
                                 "  , date_of_birth    DATE          NOT NULL " +
                                 "  , date_of_hire     DATE          NOT NULL " +
                                 "  , monthly_salary   NUMBER(15,2)  NOT NULL " +
                                 "  , position         VARCHAR2(100) NOT NULL " +
                                 "  , extension        NUMBER " +
                                 "  , office_location  VARCHAR2(100))");
                System.out.print("    - Created Table...\n");
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
         * Method used to read records from Employee.txt file then write the records
         * to an Oracle table within the database named "EMP".
        public void performLoadWrite() {
            Statement stmt          = null;
            int       insertResults = 0;
            StringTokenizer st = null;
            String  emp_id;
            String  dept_id;
            String  name;
            String  date_of_birth;
            String  date_of_hire;
            String  monthly_salary;
            String  position;
            String  extension;
            String  office_location;
            try {
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Create FileReader Object for file: " + inputFileName + "...\n");
                FileReader inputFileReader = new FileReader(inputFileName);
                System.out.print("  Create BufferedReader Object for FileReader Object...\n");
                BufferedReader inputStream   = new BufferedReader(inputFileReader);
                String inLine = null;
                while ((inLine = inputStream.readLine()) != null) {
                    st = new StringTokenizer(inLine, DELIM);
                    emp_id   = st.nextToken();
                    dept_id  = st.nextToken();
                    name     = st.nextToken();
                    date_of_birth = st.nextToken();
                    date_of_hire = st.nextToken();
                    monthly_salary = st.nextToken();
                    position = st.nextToken();
                    extension = st.nextToken();
                    office_location = st.nextToken();
                    System.out.print("  Inserting value for [" + name + "]\n");
                    insertResults = stmt.executeUpdate(
                            "INSERT INTO " + TABLE_NAME + " VALUES (" +
                                      emp_id +
                            "  ,  " + dept_id +
                            "  , '" + name + "'" +
                            "  , '" + date_of_birth + "'" +
                            "  , '" + date_of_hire + "'" +
                            "  ,  " + monthly_salary +
                            "  , '" + position + "'" +
                            "  ,  " + extension +
                            "  , '" + office_location + "')");
                    System.out.print("    " + insertResults + " row created.\n");
                System.out.print("  Commiting Transaction...\n");
                con.commit();
                System.out.print("  Closing inputString...\n");
                inputStream.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
         * Method used to query records from the database table EMP. This method
         * can be used to verify all records have been correctly loaded from the
         * example text file "Employee.txt".
        public void queryRecords() {
            Statement stmt           = null;
            ResultSet rset           = null;
            int       deleteResults  = 0;
            int       rowNumber      = 0;
            int     emp_id;
            int     dept_id;
            String  name;
            String  date_of_birth;
            Date    date_of_birth_p;
            String  date_of_hire;
            Date    date_of_hire_p;
            float   monthly_salary;
            String  position;
            int     extension;
            String  office_location;
            try {
                SimpleDateFormat formatter      = new SimpleDateFormat("yyyy-MM-dd");
                NumberFormat     defaultFormat  =     NumberFormat.getCurrencyInstance();
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Opening query for table: " + TABLE_NAME + "...\n");
                rset = stmt.executeQuery ("SELECT * FROM emp ORDER BY emp_id");
                while (rset.next ()) {
                    rowNumber = rset.getRow();
                    emp_id = rset.getInt(1);
                    if ( rset.wasNull() )   {emp_id = -1;}
                    dept_id = rset.getInt(2);
                    if ( rset.wasNull() )   {dept_id = -1;}
                    name = rset.getString(3);
                    if ( rset.wasNull() )   {name = "<null>";}
                    date_of_birth = rset.getString(4);
                    if ( rset.wasNull() ) {date_of_birth = "1900-01-01";}
                    try {
                        date_of_birth_p = formatter.parse(date_of_birth);
                    } catch (ParseException e) {
                        date_of_birth_p = new Date(0);
                    date_of_hire = rset.getString(5);
                    if ( rset.wasNull() ) {date_of_hire = "1900-01-01";}
                    try {
                        date_of_hire_p = formatter.parse(date_of_hire);
                    } catch (ParseException e) {
                        date_of_hire_p = new Date(0);
                    monthly_salary = rset.getFloat(6);
                    if ( rset.wasNull() ) {monthly_salary = 0;}
                    position = rset.getString(7);
                    if ( rset.wasNull() ) {position = "<null>";}
                    extension = rset.getInt(8);
                    if ( rset.wasNull() )   {extension = -1;}
                    office_location = rset.getString(9);
                    if ( rset.wasNull() ) {office_location = "<null>";}
                    System.out.print(
                        "\n" +
                        "  RESULTS -> [R" + rowNumber + "] " + "\n" +
                        "      Employee ID     : " + emp_id + "\n" +
                        "      Department ID   : " + dept_id + "\n" +
                        "      Employee Name   : " + name + "\n" +
                        "      D.O.B.          : " + date_of_birth_p + "\n" +
                        "      Date of Hire    : " + date_of_hire_p + "\n" +
                        "      Monthly Salary  : " + defaultFormat.format(monthly_salary) + "\n" +
                        "      Position        : " + position + "\n" +
                        "      Extension       : x" + extension + "\n" +
                        "      Office Location : " + office_location +
                        "\n");
                System.out.print("  Closing ResultSet...\n");
                rset.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
         * Close down Oracle connection.
        public void closeConnection() {
            try {
                System.out.print("  Closing Connection...\n");
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
         * Sole entry point to the class and application.
         * @param args Array of String arguments.
         * @exception java.lang.InterruptedException
         *            Thrown from the Thread class.
        public static void main(String[] args)
                throws java.lang.InterruptedException {
            WriteFileToTable runExample = new WriteFileToTable();
            runExample.createTable();
            runExample.performLoadWrite();
            runExample.queryRecords();
            runExample.closeConnection();
        }

    Hi
    Thanks a lot. I ran the program with the MySql driver as follows:
    The errors are as follows: I will ttry to place the Driver in the Classpath. As far as I know the driver has been specified correctly this time.
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at us.ilango.WriteAntennas.<init>(WriteAntennas.java:41)
         at us.ilango.WriteAntennas.main(WriteAntennas.java:377)
    java.lang.NullPointerException
         at us.ilango.WriteAntennas.createTable(WriteAntennas.java:70)
         at us.ilango.WriteAntennas.main(WriteAntennas.java:378)
    Exception in thread "main" Loading JDBC Driver -> com.mysql.jdbc.Driver
    The program is as follows:
    package us.ilango;
    * @author ilango
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.StringTokenizer;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    public class WriteAntennas {
        final static String driverClass    = "com.mysql.jdbc.Driver";
        final static String connectionURL  = "jdbc:mysql://localhost/test2";
        final static String userID         = "brian";
        final static String userPassword   = " ";
        final static String inputFileName  = "CO.DAT";
        final static String TABLE_NAME     = "CELL";
        final static String DELIM          = "|";
        Connection   con                   = null;
        public WriteAntennas() {
            try {
                System.out.print("  Loading JDBC Driver  -> " + driverClass + "\n");
                Class.forName(driverClass).newInstance();
                System.out.print("  Connecting to        -> " + connectionURL + "\n");
                this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
                System.out.print("  Connected as         -> " + userID + "\n");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
         * Method used to create the initial EMP table. Before attempting to create
         * the table, this method will first try to drop the table.
        public void createTable() {
            Statement stmt=null;
            try {
                stmt = con.createStatement();
                System.out.print("  Dropping Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
                System.out.print("    - Dropped Table...\n");
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                System.out.print("    - Table " + TABLE_NAME + " did not exist.\n");
            try {
                stmt = con.createStatement();
                System.out.print("  Creating Table: " + TABLE_NAME + "\n");
                stmt.executeUpdate("create table TOWER_PUBACC_CO (" +
         "record_type               char(2)              null" +
         ", content_indicator         char(3)              null" +
         ", file_number               char(8)              null" +
         ", registration_number       char(7)              null" +
         ", unique_system_identifier  long(9,0)         not null" +
         ", coordinate_type           char(1)              not null" +
         ",latitude_degrees          int                  null" +
         ",latitude_minutes          int                  null" +
         ",latitude_seconds          int(4,1)         null" +
         ",latitude_direction        char(1)              null" +
         ",latitude_total_seconds    int(8,1)         null" +
         ",longitude_degrees         int                  null" +
         ",longitude_minutes         int                  null" +
         ",longitude_seconds         int(4,1)         null" +
         ",longitude_direction       char(1)              null" +
         ",longitude_total_seconds   int(8,1)         null)" );
                System.out.print("   created Table...\n");
                System.out.print("  closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public void performLoadWrite() {
            Statement stmt          = null;
            int       insertResults = 0;
            StringTokenizer st = null;
            String record_type ;
            String  content_indicator;
            String file_number ;
            String registration_number;
             String unique_system_identifier ;
            String coordinate_type;
            String latitude_degrees;
            String  latitude_minutes;
            String latitude_seconds;
            String latitude_direction;
            String latitude_total_seconds;
            String longitude_degrees;
           String longitude_minutes;
           String longitude_seconds;
           String longitude_direction;
           String longitude_total_seconds;
            try {
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Create FileReader Object for file: " + inputFileName + "...\n");
                FileReader inputFileReader = new FileReader(inputFileName);
                System.out.print("  Create BufferedReader Object for FileReader Object...\n");
                BufferedReader inputStream   = new BufferedReader(inputFileReader);
                String inLine = null;
                while ((inLine = inputStream.readLine()) != null) {
                    st = new StringTokenizer(inLine, DELIM);
                    record_type   = st.nextToken();
                   content_indicator = st.nextToken();
                    file_number    = st.nextToken();
                    registration_number = st.nextToken();
                    unique_system_identifier = st.nextToken();
                   coordinate_type =st.nextToken();
                   latitude_degrees  = st.nextToken();
                   latitude_minutes = st.nextToken();
                    latitude_seconds=st.nextToken();
                   latitude_direction = st.nextToken();
                    latitude_total_seconds =st.nextToken();
                    longitude_degrees= st.nextToken();
                    longitude_minutes = st.nextToken();
                    longitude_seconds = st.nextToken();
                    longitude_direction=st.nextToken();
                    longitude_total_seconds =st.nextToken();
                    System.out.print("  Inserting value for [" + unique_system_identifier + "]\n");
                    insertResults = stmt.executeUpdate(
                            "INSERT INTO " + TABLE_NAME + " VALUES (" +
                                      record_type +
                            "  ,  " + content_indicator +
                            "  , '" + file_number + "'" +
                            "  , '" + registration_number + "'" +
                            "  , '" + unique_system_identifier + "'" +
                            "  ,  " + coordinate_type + "'" +
                            "  , '" + latitude_degrees + "'" +
                            "  ,  " + latitude_minutes + "'" +
                            "  , '" + latitude_seconds + "'" +
                            "  , '" + latitude_direction + "'" +
                            "  , '" + latitude_total_seconds + "'" +
                           "  , '" + longitude_minutes + "'" +
                           "  , '" + longitude_seconds + "'" +
                          "  , '" + longitude_direction + "'" +
                           "  , '" + longitude_total_seconds + "')");
                    System.out.print("    " + insertResults + " row created.\n");
                System.out.print("  Commiting Transaction...\n");
                con.commit();
                System.out.print("  Closing inputString...\n");
                inputStream.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
        public void queryRecords() {
            Statement stmt           = null;
            ResultSet rset           = null;
            int       deleteResults  = 0;
            int       rowNumber      = 0;
            String   record_type;
            String   content_indicator;
            String  file_number;
            String registration_number ;
            long  unique_system_identifier;
            String coordinate_type ;
            int   latitude_degrees ;
            int latitude_minutes ;
            int latitude_seconds;
            String latitude_direction;
            int  latitude_total_seconds;
            int     longitude_degrees;
             int longitude_minutes;
               int     longitude_seconds;
                 String longitude_direction;
           int  longitude_total_seconds;
            try {
                System.out.print("  Creating Statement...\n");
                stmt = con.createStatement ();
                System.out.print("  Opening query for table: " + TABLE_NAME + "...\n");
                rset = stmt.executeQuery ("SELECT * FROM cell ORDER BY unique_system_identifier");
                while (rset.next ()) {
                    rowNumber = rset.getRow();
                    unique_system_identifier = rset.getInt (1);
                    if ( rset.wasNull() )   {unique_system_identifier = -1;}
                    record_type = rset.getString (2);
                    if ( rset.wasNull() )   {record_type = "<null>";}
                    content_indicator = rset.getString(3);
                    if ( rset.wasNull() )   {content_indicator = "<null>";}
                    file_number = rset.getString(4);
                    if ( rset.wasNull() ) {file_number = "<null>";}
                    registration_number = rset.getString(5);
                    if ( rset.wasNull() ) {registration_number = "<null>";}
                    coordinate_type = rset.getString(6);
                    if ( rset.wasNull() )   {coordinate_type = "<null>";}
                    latitude_degrees = rset.getInt(7);
                    if ( rset.wasNull() ) {latitude_degrees = 1;}
    latitude_minutes = rset.getInt(8);
                    if ( rset.wasNull() ) {latitude_minutes = 1;}
    latitude_seconds = rset.getInt(9);
                    if ( rset.wasNull() ) {latitude_seconds = 1;}
    latitude_direction = rset.getString(10);
                    if ( rset.wasNull() ) {latitude_direction = "<null>";}
    latitude_total_seconds = rset.getInt(11);
                    if ( rset.wasNull() ) {latitude_total_seconds = 1;}
    longitude_degrees = rset.getInt(12);
                    if ( rset.wasNull() ) {longitude_degrees = 1;}
    longitude_minutes = rset.getInt(13);
                    if ( rset.wasNull() ) {longitude_minutes = 1;}
    longitude_seconds = rset.getInt(14);
                    if ( rset.wasNull() ) {longitude_seconds = 1;}
    longitude_direction = rset.getString(15);
                    if ( rset.wasNull() ) {longitude_direction = "<null>";}
    longitude_total_seconds = rset.getInt(16);
                    if ( rset.wasNull() ) {longitude_total_seconds = 1;}
                    System.out.print(
                        "\n" +
                        "  RESULTS -> [R" + rowNumber + "] " + "\n" +
                        "  Unique_System_Identifier         : " + unique_system_identifier  + "\n" +
                        "  Record_type     : " + record_type   + "\n" +
                        "  Content_Indicator      : " + content_indicator   + "\n" +
                        "  Registration_Number              : " + registration_number   + "\n" +
                        "  File_Number        : " +  file_number  + "\n" +
                        "  Coordinate_Type     : " + coordinate_type  + "\n" +
                        "  Latitude_Degrees          : " + latitude_degrees + "\n" +
                        "  Latitude_Minutes          : " + latitude_minutes + "\n" +
                        "  Latitude_Seconds           : " + latitude_seconds + "\n" +
                        " Latitude_Direction            : " + latitude_direction + "\n" +
                        "  Latitude_Total_Seconds           : " + latitude_total_seconds + "\n" +
                        "  Longitude_Degrees           : " + longitude_degrees + "\n" +
                        "  longitude_minutes           : " + longitude_minutes + "\n" +
                        "  Longitude_Seconds           : " + longitude_seconds + "\n" +
                       "     longitude_direction        : " + longitude_direction + "\n" +
                       "  Longitude_Total_Seconds           : " + longitude_total_seconds +
                       "\n");
                System.out.print("  Closing ResultSet...\n");
                rset.close();
                System.out.print("  Closing Statement...\n");
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public void closeConnection() {
            try {
                System.out.print("  Closing Connection...\n");
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public static void main(String[] args)
                throws java.lang.InterruptedException {
            WriteAntennas runJob = new WriteAntennas();
            runJob.createTable();
            runJob.performLoadWrite();
            runJob.queryRecords();
            runJob.closeConnection();
    }

  • JDBC MS Access--- cannot extract entry with null value with data type Meta

    I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
    The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
    Any advice will be appreciated! thanks!
    Following are the table description and JDBC code:
    test table has the following attributes:
    Field name Data Type
    name Text
    label Memo
    table contents:
    name label
    me null
    you gates
    Code:
    String query = "SELECT name, label FROM test where name like 'me' ";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next())
    String name = rs.getString("name");
    rs.getString("val");
    String label = rs.getString("label");
    System.out.println("\t"+name+"\t"+label);
    catch (SQLException ex)
    System.out.println(ex.getSQLState());
    System.out.println(ex.getErrorCode());
    System.out.println("in sqlexception");
    output:
    C:\Temp\SEFormExtractor>java DBTest
    yet SELECT name, label FROM test
    null
    0
    in sqlexception

    The question is how to extract null entry with data type memo?Okay, what you need to do is this:
    if (rs.getString("val") == null)
      // do something
    }This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception.

  • Adding to a Collection using JDBC

    I'm trying to add to a Collection via JDBC but have had no luck with getting the ResultSet into the Collection and would be grateful for some pointers in the right direction in the while (rs.next()) block:
    public void getMembers(BwGroup group) throws CalFacadeException {
         Class.forName("com.mysql.jdbc.Driver");
         String url = "jdbc:mysql://localhost/loginlist";
         Connection conn = null;
         Collection<BwPrincipal> ms = new TreeSet<BwPrincipal>();
          try {
             conn = DriverManager.getConnection(url, "user", "pword");
             PreparedStatement ps = conn.prepareStatement("SELECT * FROM list WHERE list='" + group +"'");
             ResultSet rs = ps.executeQuery();
                while (rs.next()) {
                   BwPrincipal = new bp(rs.getString(1));
                   ms = addAll(bp);
               group.setGroupMembers(ms);
               rs.close();
               ps.close();
               } catch (Exception e){
                e.printStackTrace();
               } finally {
             if (conn != null) {
            conn.close();
        }I'm getting errors regarding incompatible types for the BwPrincipal line and addAll being an unfound symbol (though I had thought that it was a method to add to Collections). If I try to call BwPrincipal as BwPrincipal bp = new bp(rs.getString(1)); then the addAll error disappears but the programme cannot see BwPrincipal as a class. I feel as if I'm going around in circles at the moment.

    BaroqueThoughts wrote:
    As you say, I'm trying to call something along the lines of
    ms= rs.getString(1);but get an incompatible string back. The reading that I had done suggested addAll but I've probably misunderstood in trying to get this to work. If I try
    ms.add(rs)then the compiler doesn't like the add method (add cannot be applied to java.sql.ResultSet)Well it can't. Why did you try that, though? To be honest, if you can't figure this out yet, JDBC is probably a step too far at the moment. Re-visit the basics, because you clearly don't understand them yet, and you'll struggle forever if you carry on down this path as-is

  • How to get comparable Oracle JDBC performance using Java 1.4 vs 1.1.7?

    Our application makes extensive use of JDBC to access an Oracle database. We wrote it a number of years ago using java 1.1.7 and we have been unable to move to new versions of java because of the performance degradation.
    I traced the problem to JDBC calls. I can reproduce the problem using a simple program that simply connects to the database, executes a simple query and then reads the data. The same program running under java 1.4 is about 60% slower than under java 1.1.7. The query is about 80% slower and getting the data is about 150% slower!
    The program is attached below. Note, I run the steps twice as the first time the times are much larger which I attribute to java doing some initializations. So the second set of values I think are more representative of the actual performance in our application where there are numerous accesses to the database. Specifically, I focus on step 4 which is the execute query command and step 5 which is the data retrieval step. The table being read has 4 columns with 170 tuples in it.
    Here are the timings I get when I run this on a Sparc Ultra 5 running
    SunOs 5.8 using an Oracle database running 8.1.7:
                     java 1.1.7  java 1.4
            overall:    2.1s         3.5s
            step 1:     30           200
            step 2:    886          2009
            step 3:      2             2
            step 4:      9            17
            step 5:    122           187
            step 6:      1             1
            step 1:      0             0
            step 2:    203           161
            step 3:      0             1
            step 4:      8            15   <-   87% slower
            step 5:     48           117   <-  143% slower
            step 6:      1             2I find the same poor performance from java versions 1.2 and 1.3.
    I tried using DataDirect's type 4 JDBC driver which gives a little better performance but overall it is still much slower than using java 1.1.7.
    Why do the newer versions of java have such poor performance when using JDBC?
    What can be done so that we can have performance similar to java 1.1.7
    using java 1.4?
    ========================================================================
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    public class test12 {
        public static void main(String args[]) {
            try {
                    long time1 = System.currentTimeMillis();
    /* step 1 */  DriverManager.registerDriver(
                        new oracle.jdbc.driver.OracleDriver());
                    long time2 = System.currentTimeMillis();
    /* step 2 */  Connection conn = DriverManager.getConnection (
                  "jdbc:oracle:thin:@dbserver1:1521:db1","user1","passwd1");
                    long time3 = System.currentTimeMillis();
    /* step 3 */  Statement stmt = conn.createStatement();
                    long time4 = System.currentTimeMillis();
    /* step 4 */  ResultSet rs = stmt.executeQuery("select * from table1");
                    long time5 = System.currentTimeMillis();
    /* step 5 */  while( rs.next() ) {
                      int message_num = rs.getInt(1);
                      String message = rs.getString(2);
                    long time6 = System.currentTimeMillis();
    /* step 6 */  rs.close(); stmt.close();
                    long time7 = System.currentTimeMillis();
                System.out.println("step 1: " + (time2 - time1) );
                System.out.println("step 2: " + (time3 - time2) );
                System.out.println("step 3: " + (time4 - time3) );
                System.out.println("step 4: " + (time5 - time4) );
                System.out.println("step 5: " + (time6 - time5) );
                System.out.println("step 6: " + (time7 - time6) );
                System.out.flush();
            } catch ( Exception e ) {
                System.out.println( "got exception: " + e.getMessage() );
            ... repeat the same 6 steps again...
    }

    If I run my sample program with the -server option, it
    takes a lot longer (6.8s vs 3.5s).Which has to be expected, as the -server option optimizes for long running programs - so it shoudl go with my second suggestion, more below...
    I am not certain what you mean by "just let the jvm
    running". Our users issue a command (in Unix) which
    invokes one of our java programs to access or update
    data in a database. I think what you are suggesting
    would require that I rewrite our application to have a
    java program always running on the users workstation
    and to also rewrite our
    commands (over a hundred) to some how pass data and
    receive data with this new server java program. That
    does not seem a very reasonable just to move to a new
    version of java. Or are you suggesting something
    else?No I was just suggestion what you descript. But if this is not an option, then maybe you should merge your java-programs to C or another native language. Or you could try the IBM-JDK with the -faststart (or similar) option. If thew Unix you mention is AIX, then there would be the option of a resetable-vm. But I cannot say if this VM would solve your problem. Java is definitly not good for applications which only issue some unqiue commands because the hotspot-compiler can not be efficiently used there. You can only try to get 1.1.7 performance by experimenting with vm-parameters (execute java -X).

  • Why does JDBC keep connections open even though I close the resultsets?

    I attached my program and my output. Please bear with me for the long output. My question here is why do the connections remain even though I closed the resultsets. I need to reuse my prepared statements, but don't want to keep the oracle sessions open. Is this possible? What do I need to do?
    If you notice in the program, I have executed the query to find the number of open sessions 5 times.
    1) After creating the connections
    2) After creating the prepared statements
    3) After executing them
    4) After getString on the resultSets
    5) After closing the resultsets.
    And the sessions are still there even is Step 5 :-(
    import java.sql.*;
    * Title:
    * Description:
    * Copyright: Copyright (c) 2001
    * Company:
    * @author
    * @version 1.0
    public class Test {
    String dburl = "jdbc:oracle:thin:@oracle92:1521:oracle92";
    String query = "select s.username,s.sid ,s.logon_time, s.serial#,sql.sql_text"+
    " from v$session s, v$sqltext sql where sql.address = "+
    "s.sql_address and sql.hash_value = s.sql_hash_value "+
    "and upper(s.username) like 'KRTEMP%'"+
    " order by s.username ,s.sid ,s.serial# ,sql.piece" ;
    // String query = "select s.username, s.sid ,s.logon_time, s.status from v$session s where upper(s.username) like 'KRTEMP%'";
    public Test(int num) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection[] con = new Connection[num];
    for(int i=0; i<num; i++) {
    con[i] = DriverManager.getConnection(dburl, "krtemp", "krtemp");
    executeQuery();
    PreparedStatement[] ps = new PreparedStatement[num];
    for(int i=0; i<num; i++) {
    ps[i] = con.prepareStatement("select * from contact");
    executeQuery();
    ResultSet[] rs = new ResultSet[num];
    for(int i=0; i<num; i++) {
    rs[i] = ps[i].executeQuery();
    executeQuery();
    for(int i=0; i<num; i++) {
    ResultSetMetaData meta = rs[i].getMetaData();
    while(rs[i].next()) {
    for(int j=1; j<=meta.getColumnCount(); j++) {
    rs[i].getString(j);
    executeQuery();
    for(int i=0; i<num; i++) {
    rs[i].close();
    executeQuery();
    private void executeQuery() throws Exception {
    Connection con = DriverManager.getConnection(dburl, "krtemp", "krtemp");
    PreparedStatement ps = con.prepareStatement(query);
    ResultSet rs = ps.executeQuery();
    ResultSetMetaData meta = rs.getMetaData();
    System.out.println("-----");
    while(rs.next()) {
    for(int i=1; i<=meta.getColumnCount(); i++) {
    System.out.print(rs.getString(i));
    System.out.print(" ");
    System.out.println();
    System.out.println("-----");
    public static void main(String[] args) throws Exception {
    Test test = new Test(5);
    The output is
    KRTEMP 9 2005-06-27 17:09:30.0 5436 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS WH
    ERE PARAMETER ='NLS_
    KRTEMP 9 2005-06-27 17:09:30.0 5436 DATE_FORMAT'
    KRTEMP 34 2005-06-26 18:51:01.0 3629 rename tstore to store
    KRTEMP 37 2005-06-27 17:09:25.0 4209 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 37 2005-06-27 17:09:25.0 4209 DATE_FORMAT'
    KRTEMP 74 2005-06-27 17:09:26.0 17625 select appId from profile_application_tabl
    e wher
    KRTEMP 74 2005-06-27 17:09:26.0 17625 e appName=:1 and appVersion=:2
    KRTEMP 83 2005-06-27 17:09:25.0 1771 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 83 2005-06-27 17:09:25.0 1771 DATE_FORMAT'
    KRTEMP 105 2005-06-27 17:09:30.0 3296 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 105 2005-06-27 17:09:30.0 3296 DATE_FORMAT'
    KRTEMP 111 2005-06-27 17:09:25.0 4878 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 111 2005-06-27 17:09:25.0 4878 DATE_FORMAT'
    KRTEMP 153 2005-06-27 17:09:30.0 31065 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 153 2005-06-27 17:09:30.0 31065 DATE_FORMAT'
    KRTEMP 163 2005-06-27 17:09:30.0 3205 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 163 2005-06-27 17:09:30.0 3205 DATE_FORMAT'
    KRTEMP 183 2005-06-27 17:09:30.0 3465 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 183 2005-06-27 17:09:30.0 3465 DATE_FORMAT'
    KRTEMP 191 2005-06-27 17:09:26.0 5438 select appId from profile_application_tabl
    e wher
    KRTEMP 191 2005-06-27 17:09:26.0 5438 e appName=:1 and appVersion=:2
    KRTEMP 256 2005-06-27 17:09:30.0 2718 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 256 2005-06-27 17:09:30.0 2718 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 256 2005-06-27 17:09:30.0 2718 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 256 2005-06-27 17:09:30.0 2718 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 9 2005-06-27 17:09:30.0 5436 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS WH
    ERE PARAMETER ='NLS_
    KRTEMP 9 2005-06-27 17:09:30.0 5436 DATE_FORMAT'
    KRTEMP 34 2005-06-26 18:51:01.0 3629 rename tstore to store
    KRTEMP 37 2005-06-27 17:09:25.0 4209 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 37 2005-06-27 17:09:25.0 4209 DATE_FORMAT'
    KRTEMP 74 2005-06-27 17:09:26.0 17625 select appId from profile_application_tabl
    e wher
    KRTEMP 74 2005-06-27 17:09:26.0 17625 e appName=:1 and appVersion=:2
    KRTEMP 83 2005-06-27 17:09:25.0 1771 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 83 2005-06-27 17:09:25.0 1771 DATE_FORMAT'
    KRTEMP 105 2005-06-27 17:09:30.0 3296 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 105 2005-06-27 17:09:30.0 3296 DATE_FORMAT'
    KRTEMP 111 2005-06-27 17:09:25.0 4878 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 111 2005-06-27 17:09:25.0 4878 DATE_FORMAT'
    KRTEMP 153 2005-06-27 17:09:30.0 31065 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 153 2005-06-27 17:09:30.0 31065 DATE_FORMAT'
    KRTEMP 163 2005-06-27 17:09:30.0 3205 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 163 2005-06-27 17:09:30.0 3205 DATE_FORMAT'
    KRTEMP 183 2005-06-27 17:09:30.0 3465 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 183 2005-06-27 17:09:30.0 3465 DATE_FORMAT'
    KRTEMP 191 2005-06-27 17:09:26.0 5438 select appId from profile_application_tabl
    e wher
    KRTEMP 191 2005-06-27 17:09:26.0 5438 e appName=:1 and appVersion=:2
    KRTEMP 232 2005-06-27 17:09:31.0 5893 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 232 2005-06-27 17:09:31.0 5893 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 232 2005-06-27 17:09:31.0 5893 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 232 2005-06-27 17:09:31.0 5893 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 34 2005-06-26 18:51:01.0 3629 rename tstore to store
    KRTEMP 37 2005-06-27 17:09:25.0 4209 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 37 2005-06-27 17:09:25.0 4209 DATE_FORMAT'
    KRTEMP 74 2005-06-27 17:09:26.0 17625 select appId from profile_application_tabl
    e wher
    KRTEMP 74 2005-06-27 17:09:26.0 17625 e appName=:1 and appVersion=:2
    KRTEMP 83 2005-06-27 17:09:25.0 1771 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 83 2005-06-27 17:09:25.0 1771 DATE_FORMAT'
    KRTEMP 111 2005-06-27 17:09:25.0 4878 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 111 2005-06-27 17:09:25.0 4878 DATE_FORMAT'
    KRTEMP 232 2005-06-27 17:09:31.0 5893 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 232 2005-06-27 17:09:31.0 5893 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 232 2005-06-27 17:09:31.0 5893 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 232 2005-06-27 17:09:31.0 5893 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 256 2005-06-27 17:09:31.0 2783 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 256 2005-06-27 17:09:31.0 2783 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 256 2005-06-27 17:09:31.0 2783 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 256 2005-06-27 17:09:31.0 2783 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 9 2005-06-27 17:09:30.0 5436 select * from contact
    KRTEMP 34 2005-06-26 18:51:01.0 3629 rename tstore to store
    KRTEMP 37 2005-06-27 17:09:25.0 4209 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 37 2005-06-27 17:09:25.0 4209 DATE_FORMAT'
    KRTEMP 74 2005-06-27 17:09:26.0 17625 select appId from profile_application_tabl
    e wher
    KRTEMP 74 2005-06-27 17:09:26.0 17625 e appName=:1 and appVersion=:2
    KRTEMP 83 2005-06-27 17:09:25.0 1771 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 83 2005-06-27 17:09:25.0 1771 DATE_FORMAT'
    KRTEMP 105 2005-06-27 17:09:30.0 3296 select * from contact
    KRTEMP 111 2005-06-27 17:09:25.0 4878 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 111 2005-06-27 17:09:25.0 4878 DATE_FORMAT'
    KRTEMP 153 2005-06-27 17:09:30.0 31065 select * from contact
    KRTEMP 163 2005-06-27 17:09:30.0 3205 select * from contact
    KRTEMP 173 2005-06-27 17:09:31.0 3922 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 173 2005-06-27 17:09:31.0 3922 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 173 2005-06-27 17:09:31.0 3922 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 173 2005-06-27 17:09:31.0 3922 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 183 2005-06-27 17:09:30.0 3465 select * from contact
    KRTEMP 191 2005-06-27 17:09:26.0 5438 select appId from profile_application_tabl
    e wher
    KRTEMP 191 2005-06-27 17:09:26.0 5438 e appName=:1 and appVersion=:2
    KRTEMP 232 2005-06-27 17:09:31.0 5893 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 232 2005-06-27 17:09:31.0 5893 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 232 2005-06-27 17:09:31.0 5893 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 232 2005-06-27 17:09:31.0 5893 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 256 2005-06-27 17:09:31.0 2783 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 256 2005-06-27 17:09:31.0 2783 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 256 2005-06-27 17:09:31.0 2783 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 256 2005-06-27 17:09:31.0 2783 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 9 2005-06-27 17:09:30.0 5436 select * from contact
    KRTEMP 34 2005-06-26 18:51:01.0 3629 rename tstore to store
    KRTEMP 37 2005-06-27 17:09:25.0 4209 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 37 2005-06-27 17:09:25.0 4209 DATE_FORMAT'
    KRTEMP 74 2005-06-27 17:09:26.0 17625 select appId from profile_application_tabl
    e wher
    KRTEMP 74 2005-06-27 17:09:26.0 17625 e appName=:1 and appVersion=:2
    KRTEMP 83 2005-06-27 17:09:25.0 1771 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS W
    HERE PARAMETER ='NLS_
    KRTEMP 83 2005-06-27 17:09:25.0 1771 DATE_FORMAT'
    KRTEMP 105 2005-06-27 17:09:30.0 3296 select * from contact
    KRTEMP 111 2005-06-27 17:09:25.0 4878 SELECT VALUE FROM NLS_INSTANCE_PARAMETERS
    WHERE PARAMETER ='NLS_
    KRTEMP 111 2005-06-27 17:09:25.0 4878 DATE_FORMAT'
    KRTEMP 153 2005-06-27 17:09:30.0 31065 select * from contact
    KRTEMP 163 2005-06-27 17:09:30.0 3205 select * from contact
    KRTEMP 183 2005-06-27 17:09:30.0 3465 select * from contact
    KRTEMP 191 2005-06-27 17:09:26.0 5438 select appId from profile_application_tabl
    e wher
    KRTEMP 191 2005-06-27 17:09:26.0 5438 e appName=:1 and appVersion=:2
    KRTEMP 204 2005-06-27 17:09:32.0 1478 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 204 2005-06-27 17:09:32.0 1478 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 204 2005-06-27 17:09:32.0 1478 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 204 2005-06-27 17:09:32.0 1478 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 232 2005-06-27 17:09:31.0 5893 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 232 2005-06-27 17:09:31.0 5893 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 232 2005-06-27 17:09:31.0 5893 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 232 2005-06-27 17:09:31.0 5893 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece
    KRTEMP 256 2005-06-27 17:09:31.0 2783 select s.username,s.sid ,s.logon_time, s.s
    erial#,sql.sql_text fr
    KRTEMP 256 2005-06-27 17:09:31.0 2783 om v$session s, v$sqltext sql where sql.ad
    dress = s.sql_address
    KRTEMP 256 2005-06-27 17:09:31.0 2783 and sql.hash_value = s.sql_hash_value and
    upper(s.username) like
    KRTEMP 256 2005-06-27 17:09:31.0 2783 'KRTEMP%' order by s.username ,s.sid ,s.s
    erial# ,sql.piece

    Why do the connections stay open? Because you haven't closed them.
    You answered your own question: obviously closing the ResultSet is NOT the same thing as closing the connection.
    When you do a query, you want to get the connection, statement, and result set, load the data from the result set into an object or data structure, and then immediately close them all again in reverse order of creation. You want to keep the scope as narrow as possible. You want to use a connection pool to keep the cost of obtaining a connection down. You should leave caching of the PreparedStatements to the JDBC driver.
    %

  • Oracle thin JDBC driver BUG-2285052, how to solve it ?

    Hi, use ResultSet.getString to get a nchar type String from databaase, it will return the proper value.
    eg, a 254 size column , it will return more char as needed !!
    please check next from jdbc readme file. anyone can give me a temp solution ?
    BUG-2285052 (since 9.2.0.1)
    Extra space and null characters are returned by ResultSet.getString() and Scrollable ResultSet getString() for NCHAR column when the database national character set is UTF8. This behavior occurs only with JDBC THIN driver.

    Dear Michael,
    thx I found a lot of useful properties via the links you provided, but not those in question.
    michael_obrien wrote:
    For timeouts, you may need to use a hint directly on the entity though
    http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_EclipseLink_JPA_Query_Hints
    http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Timeout
    I think this refers to "Statement.setQueryTimeout".
    The properties I'm looking for focus on the connection and the network beneath.
    Are there other undocumented ;) possibilities?
    Kind Regards,
    daniela

  • How to Get a BLOB Field from JDBC Coding

    Hi,
    I have written the JDBC Code to get the field values from the Table.
    There is a BLOB field in that table.
    How to get the BLOB ? What is the return type we should use.
    If it is Varchar then we can use rs.getString().
    If it is BLOB then what is the return type?
    Thanks in Advance

    Blob.
    You know, people like you really give me the urge to print out several hundred pages of Java API and smack them on their heads.

  • Help with resultset from jdbc

    When I run this program, the result set show up in the results textarea but it does not start a new line after each record even after inserting the "\n" escape character
    import java.awt.*;
    import java.sql.*;
    import java.awt.event.*;
    import javax.swing.*;
    * @author wezi
    * A java program for keeping track of the inventory of
    * books belonging to the ACM bookclub of Riverside
    public class ACMBooks extends JFrame
         private JTabbedPane mainTab;
         private JPanel connectpane, querypane, processpane, adminpane;
         private JPanel quadpane[] = new JPanel[4];
         //components for pane 1
         private JTextField txtUser, txtPort, txtHost, txtdb;
         private JLabel lbluser, lblpasswd, lblport, lblhost, lbldb, lblstatus;
         private JPasswordField pwdconnect;
         private JButton btnConnect ;
         private String tooltip[] = {"Default Name = bookdb","",
                   "Default port for MySQL = 3306",
                    "Default host is localhost", "Default database is acmbooks"};
         //Components for pane 2
         private JPanel sqlpane, searchpane, resultspane;
         private JTextArea txaSQL, txaResults;
         private JButton btnQuery, btnSearch, btnReset;
         private JLabel lblAuthor, lblTitle, lblISBN, lblCategory;
         private JTextField txtauthor, txttitle, txtisbn, txtCat;
         private JScrollPane scroller;
         //Components for panel 3
         private JPanel checkIn, checkOut;
         private GridLayout gl,gl2, gl3;
         private GridBagLayout gbl = new GridBagLayout();
         private GridBagConstraints gbc = new GridBagConstraints();
         private GridBagConstraints gbc2 = new GridBagConstraints();
         //private String pwd;
         //Set up the GUI
         public ACMBooks()
              super("ACM Book Library");
              lbldb = new JLabel("Database");
              lblstatus = new JLabel("Connection settings");
              gl = new GridLayout(2,2);
              Container cont = getContentPane();
              mainTab = new JTabbedPane();
              connectpane = new JPanel();
              adminpane = new JPanel();
              //set up the connection pane GUI
              connectpane.setLayout(gl);
              for(int i=0; i<4; i++)
                   quadpane[i] = new JPanel();
                   connectpane.add(quadpane);
              gbc.insets = new Insets(0,20,0,0);
              quadpane[0].setLayout(gbl);
              lbluser = new JLabel("User Name:");
              gbc.anchor = GridBagConstraints.NORTHEAST;
              gbc.gridx = 0; gbc.gridy = 0;
              gbc.weightx = 0.5; gbc.weighty = 0.5;
              quadpane[0].add(lbluser,gbc);
              lblpasswd = new JLabel("Password:");
              gbc.gridx = 0; gbc.gridy = 1;
              quadpane[0].add(lblpasswd,gbc);
              lblport = new JLabel("Port:");
              gbc.gridx = 0; gbc.gridy = 2;
              quadpane[0].add(lblport,gbc);
              lblhost = new JLabel("Host:");
              gbc.gridx = 0; gbc.gridy = 3;
              quadpane[0].add(lblhost,gbc);
              lbldb = new JLabel("Database:");
              gbc.gridx = 0; gbc.gridy = 4;
              quadpane[0].add(lbldb,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.insets = new Insets(0,10,0,0);
              gbc.gridx = 1; gbc.gridy = 0;
              txtUser = new JTextField(10);
              txtUser.setToolTipText("Default username = bookdb");
              quadpane[0].add(txtUser,gbc);
              gbc.gridx = 1; gbc.gridy = 2;
              txtPort = new JTextField(10);
              txtPort.setToolTipText("Default port = 3306");
              quadpane[0].add(txtPort,gbc);
              gbc.gridx = 1; gbc.gridy = 3;
              txtHost = new JTextField(10);
              txtHost.setToolTipText("Default host = localhost");
              quadpane[0].add(txtHost,gbc);
              gbc.gridx = 1; gbc.gridy = 4;
              txtdb = new JTextField(10);
              txtdb.setToolTipText("Default database = acmbooks");
              quadpane[0].add(txtdb,gbc);
              pwdconnect = new JPasswordField(10);
              gbc.gridx = 1; gbc.gridy = 1;
              quadpane[0].add(pwdconnect,gbc);
              //Create a connection button
              btnConnect = new JButton("Connect");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2; gbc.gridy = 4;
              quadpane[0].add(btnConnect,gbc);
              //create the reset button
              btnReset = new JButton(" Reset ");
              btnReset.setSize(btnConnect.getHeight(),btnConnect.getWidth());
              gbc.gridx = 2; gbc.gridy = 3;
              quadpane[0].add(btnReset,gbc);
    //Connection status
              lblstatus = new JLabel();
              quadpane[3].setLayout(gbl);
              gbc.anchor = GridBagConstraints.SOUTHEAST;
              gbc.insets = new Insets(0,10,20,20);
              quadpane[3].add(lblstatus,gbc);
              //Add a border to the first pane & add it to the main container
              quadpane[0].setBorder(BorderFactory.createTitledBorder("Details"));
              mainTab.addTab("Connection Settings",null,connectpane,"connections");
              //Create the second tab (Query pane)
              querypane = new JPanel();
              GridBagLayout gblquery= new GridBagLayout();
              GridBagConstraints gbcquery = new GridBagConstraints();
              gl2 = new GridLayout(4,1);
              querypane.setLayout(gblquery);
              //The sql query pane
              sqlpane = new JPanel();
              sqlpane.setLayout(gbl);
              gbc2.gridx = 0; gbc2.gridy = 0;
              gbc2.weightx = 0.5; gbc2.weighty = 0.5;
              txaSQL = new JTextArea(4,44);
              txaSQL.setBorder(BorderFactory.createLoweredBevelBorder());
              gbc2.anchor = GridBagConstraints.NORTHWEST;
              gbc2.insets = new Insets(0,10,0,0);
              sqlpane.add(txaSQL,gbc2);
              gbc2.gridx = 1; gbc2.gridy = 0;
              btnQuery = new JButton("Enter Query");
              gbc2.insets = new Insets(0,16,5,10);
              gbc2.anchor = GridBagConstraints.SOUTHEAST;
              sqlpane.add(btnQuery,gbc2);
              sqlpane.setBorder(BorderFactory.createTitledBorder("SQL Queries:"));
              gbcquery.gridheight =1; gbcquery.gridwidth = 1;
              gbcquery.gridx = 0; gbcquery.gridy = 0;
              gbcquery.anchor = GridBagConstraints.NORTHWEST;
              gbcquery.weightx = 0.5; gbcquery.weighty =0.5;
              gbcquery.fill =GridBagConstraints.REMAINDER;
              gbcquery.insets = new Insets(0,0,2,0);
              gbcquery.ipadx = 1; gbcquery.ipady = 1;
              querypane.add(sqlpane,gbcquery);
              //The search by pane
              searchpane = new JPanel();
              searchpane.setLayout(gbl);
              gbc2.insets = new Insets(0,14,5,5);
              lblAuthor = new JLabel("Author:");
              gbc2.anchor = GridBagConstraints.NORTHEAST;
              gbc2.gridx = 0; gbc2.gridy = 0;
              searchpane.add(lblAuthor,gbc2);
              lblTitle = new JLabel("Title:");
              gbc2.gridx = 0; gbc2.gridy = 1;
              searchpane.add(lblTitle,gbc2);
              lblISBN = new JLabel("ISBN:");
              gbc2.gridx = 2; gbc2.gridy = 0;
              searchpane.add(lblISBN,gbc2);
              lblCategory = new JLabel("Category:");
              gbc2.gridx = 2; gbc2.gridy =1;
              searchpane.add(lblCategory,gbc2);
              txtauthor = new JTextField(15);
              gbc2.gridx = 1; gbc2.gridy = 0;
              gbc2.anchor = GridBagConstraints.NORTHWEST;
              searchpane.add(txtauthor,gbc2);
              txttitle = new JTextField(15);
              gbc2.gridx = 1; gbc2.gridy = 1;
              searchpane.add(txttitle,gbc2);
              txtisbn = new JTextField(15);
              gbc2.gridx = 3; gbc2.gridy = 0;
              searchpane.add(txtisbn,gbc2);
              txtCat = new JTextField(15);
              gbc2.gridx = 3; gbc2.gridy = 1;
              searchpane.add(txtCat,gbc2);
              btnSearch = new JButton("Search >>>");
              gbc2.anchor = GridBagConstraints.SOUTHEAST;
              gbc2.gridx = 4; gbc2.gridy = 1;
              gbc2.insets = new Insets(0,5,20,10);
              searchpane.add(btnSearch,gbc2);
              searchpane.setBorder(BorderFactory.createTitledBorder("Search By:"));
              gbcquery.gridheight =1; gbcquery.gridwidth = 1;
              gbcquery.gridx = 0; gbcquery.gridy = 1;
              gbcquery.insets = new Insets(0,0,0,0);
              querypane.add(searchpane,gbcquery);
              //The results pane
              resultspane = new JPanel();
              resultspane.setSize(20,60);
              resultspane.setLayout(gbl);
              gbc2.gridx = 0; gbc2.gridy = 0;
              gbc2.anchor = GridBagConstraints.NORTHWEST;
              txaResults = new JTextArea(" ",9,55);
              scroller = new JScrollPane(txaResults);
              resultspane.add(new JScrollPane(txaResults));
              txaResults.setBorder(BorderFactory.createLoweredBevelBorder());
              resultspane.add(txaResults,gbc2);
              resultspane.setBorder(BorderFactory.createTitledBorder("Results:"));
              gbcquery.gridheight =3; gbcquery.gridwidth = 1;
              gbcquery.gridx = 0; gbcquery.gridy = 2;
              gbcquery.weightx = 1; gbcquery.weighty = 1;
              querypane.add(resultspane,gbcquery);
              mainTab.addTab("Query Entry",null,querypane,"Query page");
              //Create a third tab to process book checkin and out
              processpane = new JPanel();
              gl3 = new GridLayout(4,1);
              processpane.setLayout(gl3);
              //Create the checkin panel
              checkIn = new JPanel();
              checkIn.setBorder(BorderFactory.createTitledBorder("Return Books"));
              checkIn.setLayout(gbl);
              //Create the checkout panel
              checkOut = new JPanel();
              checkOut.setBorder(BorderFactory.createTitledBorder("Check Books Out"));
              processpane.add(checkOut,gl3);
              processpane.add(checkIn,gl3);
              mainTab.addTab("Process Books",null, processpane,"Book Processing page");
              //Create an administration panel
              adminpane = new JPanel();
              mainTab.addTab("Admin",null,adminpane,"Administration page");
              cont.add(mainTab);
              //Register the eventhandlers
              ButtonHandler btnHandler = new ButtonHandler();
              btnConnect.addActionListener(btnHandler);
              btnQuery.addActionListener(btnHandler);
              btnSearch.addActionListener(btnHandler);
              btnReset.addActionListener(btnHandler);
              setSize(650,460);
              setVisible(true);
         }//end constructor
         private class ButtonHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                   String errMsg;
                   Statement stmt;
                   ResultSet rs;
                   Connection con = null;
                   String pwd;
                   String user;
                   //Create a url from user input
                   String url = "jdbc:mysql://";
                   url += txtHost.getText();
                   url += ":";
                   url += txtPort.getText();
                   url += "/";
                   url += txtdb.getText();
              try
                   //Register the JDBC Mysql Driver
                   Class.forName("com.mysql.jdbc.Driver");
                   //Get the password and user name for the database
                   pwd = new String(pwdconnect.getPassword());
                   user = new String(txtUser.getText());
                   //Open a connection to the database
                   con = DriverManager.getConnection(url,user,pwd);
                        //Add the action event for the btnReset
                        if(e.getSource() == btnReset)
                             //Clear all the text fields and the status label
                             lblstatus.setText(" ");
                             txtUser.setText(" ");
                             txtdb.setText(" ");
                             txtHost.setText(" ");
                             txtPort.setText(" ");
                             pwdconnect.setText("");
                             txaResults.setText(" ");
                             txaSQL.setText(" ");
                             try{
                                  if(!con.isClosed())
                                       con.close();
                             catch(Exception closeError)
                                  String clErr = new String(closeError.toString());
                                  txaResults.setText(clErr);
                        }//end btnReset
                   //If the connect button is pressed
                   if(e.getSource() == btnConnect)
                   if(!con.isClosed())//if connection is open
                        lblstatus.setText("");
                        lblstatus.setVisible(true);
                        lblstatus.setText("Connected to " + txtdb.getText()
                             +" on "     + txtHost.getText());
                   else
                   { lblstatus.setText("Not Connected"); }
                   }//end btnConnect
                   if(e.getSource() == btnQuery || e.getSource()== txaSQL)
                        String strQuery = new String(txaSQL.getText());
                        ResultSetMetaData rsmtd;
                        int numCol;
                        try
                             stmt = con.createStatement();
                             rs = stmt.executeQuery(strQuery);
                             rsmtd = rs.getMetaData(); //to get metadata
                             numCol = rsmtd.getColumnCount(); //for number of columns
                             String strCol[] = new String[numCol];
                             String colName[] = new String[numCol];
                             String txaColumn = new String("");
                             String strHeading = new String("");
                             //Write the results of the query to the results text area
                             txaResults.setText(" ");          
                             //Get the data from the result set
                             //first get the column headings
                             for(int i=1; i<=numCol; i++)
                                  colName[i-1] = rsmtd.getColumnName(i);
                                  strHeading += colName[i-1] + "\t";
                             txaResults.setText(strHeading + "\n");
                             while(rs.next())
                                  //Get the values & create a display column
                                  for(int i=1; i<=numCol; i++)
                                       strCol[i-1] = rs.getString(i);
                                       txaColumn += strCol[i-1] + "\t";
                                  }//end for
                                  //Display the values
                                  txaResults.append( txaColumn + "\n");
                        catch(Exception sqlError)
                             txaResults.setText("");
                             String strSqlErr = new String(sqlError.toString());
                             txaResults.setText(strSqlErr);
                   }//end btnQuery
                   if(e.getSource() == btnSearch)
                        try
                             String strAuthor = new String(txtauthor.getText());
                             String strISBN = new String(txtisbn.getText());
                             String strTitle = new String(txttitle.getText());
                             String strCat = new String(txtCat.getText());
                             * Need to add code to change the search fields to
                             * any if the field is blank i.e if the field is blank
                             * search using a wild card. If all fields are blank, then
                             * do not search at all.
                             stmt = con.createStatement();
                             rs = stmt.executeQuery("Select * from books where" +
                                       " bookAuthor = " + strAuthor +
                                       " bookISBN = " + strISBN +
                                       " bookTitle = " + strTitle +
                                       "bookCategory = " + strCat);
                        catch(Exception searchError)
                             errMsg = new String(searchError.toString());
                             txaResults.setText("");
                             txaResults.setText(errMsg);
                   }//end btnSearch
              catch(Exception connectError)
                   errMsg = new String(connectError.toString());
                   lblstatus.setText("");
                   lblstatus.setText(errMsg);
              }//end actionPer
         }//end ButtonHandler
         public static void main(String[] args)
              ACMBooks app = new ACMBooks();
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         }//end main
    }//end class ACMBooks

    Hi,
    Here is a template of Manifest file which you can use for your reference:
    Manifest-Version: 1.0
    Created-By: Apache Ant 1.5.1
    Main-Class: com.pkg1.pkg2.MainClass
    Class-Path: . ./libs/ ./libs/database-driver.jar ./libs/jdom.jar ./libs/xercesImpl.jar ./libs/log4j.jar ....
    Name: com.pkg1.pkg2Main-Class: Specify the main class with complete package name
    Class-Path: Put all the jar file name with path
    <b>So the solution to your problem is to put you jar file name with the relative or complete path</b>
    Thanks
    Duke.

  • Error when run Application with jdbc  Help me please

    this my code:
    public void resultado() {
    String ClassName = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@educacion04:1521:ora92";
    Connection con;
    Statement stmt;
    try {
    Class.forName(ClassName);
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    try {
    con = DriverManager.getConnection(url,"ora1", "oracle");
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    ResultSet uprs = stmt.executeQuery("SELECT * FROM ANEXO ");
    uprs.moveToInsertRow();
    uprs.updateString("cod_ane", "uno");
    uprs.updateString("cod_informe", "dos");
    uprs.updateString("", "tres");
    uprs.insertRow();
    uprs.updateString("cod_ane", "cuatro");
    uprs.updateString("cod_informe", "cinco");
    uprs.updateString("desc_anexo", "seis");
    uprs.insertRow();
    uprs.beforeFirst();
    System.out.println("Table ANEXO after insertion:");
    while (uprs.next()) {
    String name = uprs.getString("cod_ane");
    String id = uprs.getString("cod_informe");
    String price = uprs.getString("desc_anexo");
    System.out.print(name + " " + id + " " + price);
    uprs.close();
    stmt.close();
    con.close();
    con.commit();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    WHEN CALL FUNCTION?????
    send this:
    ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    SQLException: No suitable driver

    Are you sure Oracle driver (classes12.jar or classes12.zip) is in your classpath ???

Maybe you are looking for