Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 40018 invoked from network); 16 Nov 2007 09:49:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Nov 2007 09:49:37 -0000 Received: (qmail 98442 invoked by uid 500); 16 Nov 2007 09:49:20 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 98414 invoked by uid 500); 16 Nov 2007 09:49:20 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 98398 invoked by uid 99); 16 Nov 2007 09:49:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 01:49:20 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [206.190.38.206] (HELO web51601.mail.re2.yahoo.com) (206.190.38.206) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 16 Nov 2007 09:49:09 +0000 Received: (qmail 77831 invoked by uid 60001); 16 Nov 2007 09:49:01 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=3wpGKURrwcR/A0vI9bKcz1iJ8AOI6J1AD4f+d214YiEngA6/jrgFXNKz4TJG+AImbI2oC4395AGZTRtM1/Z0SaY6ssmeBJK84TREo5iBicGwBrPfALgqeqRJsIWP+6nbHN+sl0TlKPex4psZeel/bQC1z7ISx3XZBjKjMgkK09s=; X-YMail-OSG: nTsYaaAVM1k0xloUj56i_65c9gQs6yJcvJvUBbIKADVxzF2txCdNnnaXNfghoYGDPWYXZSlivoqDIdg4nY7F9CqPWg-- Received: from [196.12.47.8] by web51601.mail.re2.yahoo.com via HTTP; Fri, 16 Nov 2007 01:49:01 PST Date: Fri, 16 Nov 2007 01:49:01 -0800 (PST) From: Aneez Backer Subject: Re: Newbie Blues : Unable to connect to derby database using JDBC To: Derby Discussion In-Reply-To: <473D6550.6050908@sun.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1635230721-1195206541=:77264" Content-Transfer-Encoding: 8bit Message-ID: <309835.77264.qm@web51601.mail.re2.yahoo.com> X-Virus-Checked: Checked by ClamAV on apache.org --0-1635230721-1195206541=:77264 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hi Jorgen Thanks for the response. That helped !!!!!!! thanks once again Aneez J�rgen L�land wrote: 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 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 --------------------------------- Never miss a thing. Make Yahoo your homepage. --0-1635230721-1195206541=:77264 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hi Jorgen

Thanks for the response. That helped !!!!!!!

thanks once again
Aneez

J�rgen L�land <Jorgen.Loland@Sun.COM> wrote:
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 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





Never miss a thing. Make Yahoo your homepage. --0-1635230721-1195206541=:77264--