You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Aneez Backer <an...@yahoo.com> on 2007/11/16 05:47:35 UTC
Newbie Blues : Unable to connect to derby database using JDBC
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.
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Aneez Backer <an...@yahoo.com> writes:
> exception thrown:
> java.sql.SQLDataException: Invalid character string format for type int.
Sounds like you're calling ResultSet.getInt() on a string column. Could
that be the case?
--
Knut Anders
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Jørgen Løland <Jo...@Sun.COM>.
One more thing...
Your query
"SELECT firstname, lastname FROM USERS WHERE uid = 1001
will never return more than one row since uid is primary key. Hence, the
SimpleApp1 code will throw an exception on line 73 even if you change
the query as suggested in the previous comment.
I wonder if you are misinterpreting the "row" and "column" terms in
ResultSets? Assume the following information is in your table:
uid firstname lastname
--- --------- --------
1000 Sam Gamgee
1001 Legolas Greenleaf
1002 Peregrin Took
Your query would return 1 row with two columns:
"Legolas" and "Greenleaf"
To print this information, you should do:
rs.next(); // Current row is now 1, which is Legolas Greenleaf
System.out.println("This is person # 1001");
System.out.println("Firstname: "+rs.getString(1));
System.out.println("Lastname: "+rs.getString(2));
Which would print:
This is person # 1001
Firstname: Legolas
Lastname: Greenleaf
If you instead had a query
"SELECT uid, firstname, lastname FROM USERS"
you would get a ResultSet with three rows and three columns, and you
could print them like this:
rs.next(); // now on row 1, which is Sam Gamgee
System.out.println("This is person # "+rs.getInt(1)); //column 1 is uid
System.out.println("Firstname: "+rs.getString(2));
System.out.println("Lastname: "+rs.getString(3));
rs.next(); // now on row 2, which is Legolas Greenleaf
...
or better:
while (rs.next()) {
System.out.println("This is person # "+rs.getInt(1));
System.out.println("Firstname: "+rs.getString(2));
System.out.println("Lastname: "+rs.getString(3));
}
Hope this helped.
--
Jørgen Løland
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
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by John Embretsen <Jo...@Sun.COM>.
Aneez,
I see that your class is based on Derby's simple demo. Once you start modifying
the database or parts of the demo code, care should be taken to ensure that the
rest of the code is still valid. For example, the data verification part is very
specific to the data inserted by the demo.
If you need more info on how to work with JDBC (for example ResultSets), I
recommend this tutorial:
http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
--
John
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.
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Aneez Backer <an...@yahoo.com>.
Hi Jorgen
Thanks for the response. That helped !!!!!!!
thanks once again
Aneez
Jørgen Løland <Jo...@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.
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Jørgen Løland <Jo...@Sun.COM>.
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 <Th...@Sun.COM> 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
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Aneez Backer <an...@yahoo.com>.
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 <Th...@Sun.COM> 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
>
>
--
Thomas Nielsen
---------------------------------
Get easy, one-click access to your favorites. Make Yahoo! your homepage.
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Thomas Nielsen <Th...@Sun.COM>.
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 <Oy...@Sun.COM>/* 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.
>>>> <http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
>>> --
>>> Thomas Nielsen
>
>
--
Thomas Nielsen
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by "Bernt M. Johnsen" <Be...@Sun.COM>.
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 <Oy...@Sun.COM>/* 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.
> > ><http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
> >
> > --
> > Thomas Nielsen
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by "Bernt M. Johnsen" <Be...@Sun.COM>.
>>>>>>>>>>>> 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 <Oy...@Sun.COM>/* 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.
> ><http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
>
> --
> Thomas Nielsen
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Thomas Nielsen <Th...@Sun.COM>.
It would probably be better to simply do
catch (Throwable e)
{
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 <Oy...@Sun.COM>/* 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.
> <http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
--
Thomas Nielsen
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Aneez Backer <an...@yahoo.com>.
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 <Oy...@Sun.COM> 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.
Re: Newbie Blues : Unable to connect to derby database using JDBC
Posted by Øystein Grøvlen <Oy...@Sun.COM>.
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.
> <http://us.rd.yahoo.com/evt=51443/*http://www.yahoo.com/r/hs>