db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Nielsen <Thomas.Niel...@Sun.COM>
Subject Re: Newbie Blues : Unable to connect to derby database using JDBC
Date Fri, 16 Nov 2007 09:02:50 GMT
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 <Oystein.Grovlen@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

Mime
View raw message