Hi Aneez

The codeline that causes you trouble is this:

line 66: if (rs.getInt(1) != 300)

Looking at your select query, what you try to do here is to get an integer from the "firstname" column (firstname is column number 1).

If you are trying to get the integer stored in the uid column, you need to add it to the select query like this:

select uid, firstname, lastname from users where uid=1001

If this is what you want, rs.getInt(1) will never be 300, though. The query specifies that only the row with uid 1001 will be returned.

Aneez Backer wrote:
Hi

I have attached the Java source file. The error is as follows when I run the 
program:

------------------------------

SimpleApp starting in embedded mode.
Loaded the appropriate driver.
Connected to 24k
exception thrown:
java.sql.SQLDataException: Invalid character string format for type int.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unkn
own Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source
)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException
(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unkn
own Source)
        at org.apache.derby.impl.jdbc.EmbedResultSet.getInt(Unknown Source)
        at SampleApp1.go(SampleApp1.java:66)
        at SampleApp1.main(SampleApp1.java:23)
Caused by: java.sql.SQLException: Invalid character string format for type int.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknow
n Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport
AcrossDRDA(Unknown Source)
        ... 7 more
Caused by: ERROR 22018: Invalid character string format for type int.
        at org.apache.derby.iapi.error.StandardException.newException(Unknown So
urce)
        at org.apache.derby.iapi.types.SQLChar.getInt(Unknown Source)
        ... 3 more
SampleApp finished

------------------------------------------------

When I run the same query through the 'ij' tool on the console, it works fine.
The create table statement is as follows:

CREATE TABLE USERS(
uid BIGINT PRIMARY KEY,
email VARCHAR(50) UNIQUE NOT NULL,
passwd VARCHAR(15) NOT NULL,
firstname VARCHAR(20),
lastname VARCHAR(20),
date_of_birth DATE,
place VARCHAR(50),
aboutme VARCHAR(500),
myblog VARCHAR(50)
);

Am using db-derby-10.3.1.4-bin. So , the version is 10.3


Looking forward for comments
Thanks
-Aneez




Thomas Nielsen <[EMAIL PROTECTED]> wrote: Bernts point is still very valid - you should catch Exception, not Throwable. My bad!

    catch (Exception e)
    {
       System.out.println("exception thrown:");
       e.printStackTrace();
    }

BR
Thomas
off to get more liquid Java...

Bernt M. Johnsen wrote:
Sorry, this one was intended only for Thomas. Please disregard :-))


Bernt M. Johnsen wrote (2007-11-16 09:56:00):
Thomas Nielsen wrote (2007-11-16 08:17:17):
It would probably be better to simply do

   catch (Throwable e)
Neineinei..... aldri be nybegynnere gjøre "catch Throwable". Det skal
man ligge langt unna helt til man er så erfaren at man faktisk vet hva
det innebærer. Denne vil cathe Error som du får f.eks. ved VM-feil,
hw-feil etc.

catch Exception er ok for debugging, men ikke i produksjonskode.

catch SQLException er det riktige



   {
      System.out.println("exception thrown:");
      e.printStackTrace();
   }

to get the full stacktrace for the SQLException that you see as well.

And just for the record, what version of derby are you using ?

BR,
Thomas


Aneez Backer wrote:
Hi

This is what is being printed on the console.
The error message is in bold

Loaded the appropriate driver.
Connected to database  24k
exception thrown:
java.sql.SQLDataException: Invalid character string format for type
int.


The catch statement is as follows:-

       catch (Throwable e)
       {
           System.out.println("exception thrown:");

           if (e instanceof SQLException)
           {
               printSQLError((SQLException) e);
           }
           else
           {
               e.printStackTrace();
           }
       }




Hope that clears the picture??

Thnaks
Aneez
*/Øystein Grøvlen /* wrote:

   Aneez,

   Can you provide the call stack for the exception you get?

   --
   Øystein


   Aneez Backer wrote:
    > Hi
    >
> Am trying to connect to derby database, but have not been successful.
    >
    > I have created a database called 24k , and have also populated
   the tables
    >
    > Here's the code:
    >
    > ---------------------------------
    >
    > org.apache.derby.jdbc.EmbeddedSimpleDataSource ds = null;
    > Connection conn = null;
    > Properties props = new Properties();
    > props.put("user", username);
    > props.put("", "");
    >
    > Class.forName(driver).newInstance();
    > System.out.println("Loaded the appropriate driver.");
    >
    > conn = DriverManager.getConnection(protocol +"24k;", props);
    > System.out.println("Connected to database 24k");
    >
    > conn.setAutoCommit(false);
    >
    > Statement s = conn.createStatement();
    >
    > ResultSet rs = s.executeQuery("SELECT firstname, lastname
    > FROM USERS WHERE uid = 1001");
    >
    > ---------------------------------------------------------------
    >
    >
    > ---------------------------------------------------------------
    > ERROR
    > ---------------------------------------------------------------
    >
    >
    >
    >
    > Loaded the appropriate driver.
    > Connected to database 24k
    > exception thrown:
    > java.sql.SQLDataException: Invalid character string format for
   type int.
    >
    > ---------------------------------------------------------------
    >
    > Please guide
    >
    > Thanks
    > Aneez
    >
    >
    >
    >
    >
   ------------------------------------------------------------------------
    > Get easy, one-click access to your favorites. Make Yahoo! your
   homepage.
    >





------------------------------------------------------------------------
Never miss a thing. Make Yahoo your homepage.
--
Thomas Nielsen




--
Jørgen Løland

Reply via email to