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 john miltone <mi...@gmail.com> on 2013/02/23 12:21:00 UTC

DriverManager.getConnection error with JDK 7

Hi All,

 

I am starting into Derby and I develop on Intellij IDEA with JDK 7.

I just want to create and start database. It seems very simple but the first
and unique code row generate a exception.

Can you help me to understand and arrive to start engine Derby database in
my program please ?

 

Here this is my code :

"

    public static void main (String[] args) throws IOException

    {

        String dbName = "MoneyBack1";

        String user = "miltone";

        String password = "password";

        String connectionURL = "jdbc:derby:" + dbName + ";create=true;user="
+ user + ";password=" + password ;

        String createString = "CREATE TABLE operation " + "(operation_ID INT
NOT NULL GENERATED ALWAYS AS IDENTITY " + " type VARCHAR(32) NOT NULL) " ;

 

        try

        {

            Connection connexion =
DriverManager.getConnection(connectionURL);

            Statement statement = connexion.createStatement();

            statement.executeQuery(createString);

            statement.close();

            connexion.close();

        }

        catch (Throwable e)

        {

            System.out.println("1");

        }

"

 

DriverManager.getConnection throw a exeception always.

I'm using JDK 1.7.0_10 so then I don't use ClassName methods for bring
driver into memory.

 

Thank a lot for all helping.


Re: DriverManager.getConnection error with JDK 7

Posted by "George S." <ge...@mhsoftware.com>.
You might want to read this page and resubmit the question.

http://www.catb.org/esr/faqs/smart-questions.html

In particular, you might want to post the command line used to invoke 
Java, and post the text of the error. Also, can you explain the part 
about not using class for name?

On 2/23/13 4:21 AM, john miltone wrote:
>
> Hi All,
>
> I am starting into Derby and I develop on Intellij IDEA with JDK 7.
>
> I just want to create and start database. It seems very simple but the 
> first and unique code row generate a exception.
>
> Can you help me to understand and arrive to start engine Derby 
> database in my program please ?
>
> Here this is my code :
>
> "
>
>     public static void main (String[] args) throws IOException
>
>     {
>
>         String dbName = "MoneyBack1";
>
>         String user = "miltone";
>
>         String password = "password";
>
>         String connectionURL = "jdbc:derby:" + dbName + 
> ";create=true;user=" + user + ";password=" + password ;
>
>         String createString = "CREATE TABLE operation " + 
> "(operation_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY " + " type 
> VARCHAR(32) NOT NULL) " ;
>
> try
>
>         {
>
>             Connection connexion = 
> DriverManager.getConnection(connectionURL);
>
>             Statement statement = connexion.createStatement();
>
> statement.executeQuery(createString);
>
> statement.close();
>
> connexion.close();
>
>         }
>
>         catch (Throwable e)
>
>         {
>
> System.out.println("1");
>
>         }
>
> "
>
> DriverManager.getConnection throw a exeception always.
>
> I'm using JDK 1.7.0_10 so then I don't use ClassName methods for bring 
> driver into memory.
>
> Thank a lot for all helping.
>

-- 
George Sexton
MH Software, Inc.
303 438-9585
http://www.mhsoftware.com/


Re: DriverManager.getConnection error with JDK 7

Posted by John English <jo...@gmail.com>.
On 23/02/2013 13:21, john miltone wrote:
> Hi All,
>
> I am starting into Derby and I develop on Intellij IDEA with JDK 7.
>
> I just want to create and start database. It seems very simple but the first and
> unique code row generate a exception.
>
>          String createString = "CREATE TABLE operation " + "(operation_ID INT
> NOT NULL GENERATED ALWAYS AS IDENTITY " + " type VARCHAR(32) NOT NULL) " ;

Looks like you're missing a comma after AS IDENTITY; the statement should be:

   CREATE TABLE operation (
     operation_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY,
     type VARCHAR(32) NOT NULL
   )

The exception is presumably reporting a syntax error, but since you didn't give 
details of the exception I can't be sure.

-- 
John English

RE: DriverManager.getConnection error with JDK 7

Posted by john miltone <mi...@gmail.com>.
Hello Katherine Marsden,

I haven't the java org.apache.derby.tools.sysinfo in my jdk 7 directory and
classpath.
It's very strange because I can create and manage Derby with jdk7 (directory
db in installation path) but there is no class in my classpath for run
directly ?

When I am in my IDE


-----Message d'origine-----
De : Katherine Marsden [mailto:kmarsdenderby@sbcglobal.net] 
Envoyé : dimanche 24 février 2013 15:30
À : Derby Discussion
Objet : Re: DriverManager.getConnection error with JDK 7

On 2/24/2013 6:19 AM, john miltone wrote:
> I don't find where is my problem with this information sysinfo tool derby
:
>
> Microsoft Windows [version 6.1.7601]
> Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.
>
> C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib>java -jar derbyrun.jar 
> sysinfo

Since you want to test your classpath just use that instead of using -jar
derbyrun.jar , so try

java org.apache.derby.tools.sysinfo

and
echo %CLASSPATH%

Then hopefully the problem with your classpath will become apparent.


Re: DriverManager.getConnection error with JDK 7

Posted by Katherine Marsden <km...@sbcglobal.net>.
On 2/24/2013 6:19 AM, john miltone wrote:
> I don't find where is my problem with this information sysinfo tool derby :
>
> Microsoft Windows [version 6.1.7601]
> Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.
>
> C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib>java -jar derbyrun.jar
> sysinfo

Since you want to test your classpath just use that instead of using 
-jar derbyrun.jar , so try

java org.apache.derby.tools.sysinfo

and
echo %CLASSPATH%

Then hopefully the problem with your classpath will become apparent.


RE: DriverManager.getConnection error with JDK 7

Posted by john miltone <mi...@gmail.com>.
I don't find where is my problem with this information sysinfo tool derby :

Microsoft Windows [version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.

C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib>java -jar derbyrun.jar
sysinfo
------------------ Informations Java  ------------------
Version Java :    1.7.0_13
Fournisseur Java :     Oracle Corporation
RÚpertoire principal Java :       C:\Program Files (x86)\Java\jre7
Chemin de classes Java :  derbyrun.jar
Nom du systÞme d'exploitation :         Windows 7
Architecture du systÞme d'exploitation :         x86
Version du systÞme d'exploitation :         6.1
Nom d'utilisateur Java :  ymersion
RÚpertoire principal utilisateur Java :  C:\Users\ymersion
RÚpertoire utilisateur Java :   C:\Program Files
(x86)\Java\jdk1.7.0_10\db\lib
java.specification.name: Java Platform API Specification
java.specification.version: 1.7
java.runtime.version: 1.7.0_13-b20
--------- Informations Derby --------
JRE - JDBC: Java SE 7 - JDBC 4.0
[C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib\derby.jar] 10.8.2.2 -
(1181258)
[C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib\derbytools.jar] 10.8.2.2 -
(1181
258)
[C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib\derbynet.jar] 10.8.2.2 -
(118125
8)
[C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib\derbyclient.jar] 10.8.2.2 -
(118
1258)
------------------------------------------------------
----------------- Informations sur l'environnement local -----------------
Environnement local actuel :  [franþais/France [fr_FR]]
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [cs]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [de_DE]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [es]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [fr]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [hu]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [it]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [ja_JP]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [ko_KR]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [pl]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [pt_BR]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [ru]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [zh_CN]
         version : 10.8.2.2 - (1181258)
La prise en charge de cet environnement local a ÚtÚ trouvÚe : [zh_TW]
         version : 10.8.2.2 - (1181258)
------------------------------------------------------

C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib>



-----Message d'origine-----
De : Bryan Pendleton [mailto:bpendleton.derby@gmail.com] 
Envoyé : samedi 23 février 2013 18:06
À : Derby Discussion
Objet : Re: DriverManager.getConnection error with JDK 7

>> I caught SQLException and he said that : "No suitable driver found 
>> for jdbc:derby:MoneyBack1;create=true;user=miltone;password=password"
>
> So your classloader can't find the derby driver. Have you checked that
derby.jar is on your classpath?

The sysinfo tool is useful for diagnosing classpath problems like these:

http://db.apache.org/derby/docs/10.9/getstart/tgsrunningsysinfo.html

thanks,

bryan


RE: DriverManager.getConnection error with JDK 7

Posted by john miltone <mi...@gmail.com>.
Hello,

I find my problem. 
All the issue resume to simple sentence. I think JDK 7 embedded in its
classpath the Derby driver class.
It's more confuse because in a path OS installation java jdk7 there is a
directory db with bin and lib Derby.

It's packed with jdk but not really integrated. The manual reference, Derby
developer guide and get started not speak to this mean very well.

Thank for your help I can use finally Derby 8-)
 

-----Message d'origine-----
De : Bryan Pendleton [mailto:bpendleton.derby@gmail.com] 
Envoyé : samedi 23 février 2013 18:06
À : Derby Discussion
Objet : Re: DriverManager.getConnection error with JDK 7

>> I caught SQLException and he said that : "No suitable driver found 
>> for jdbc:derby:MoneyBack1;create=true;user=miltone;password=password"
>
> So your classloader can't find the derby driver. Have you checked that
derby.jar is on your classpath?

The sysinfo tool is useful for diagnosing classpath problems like these:

http://db.apache.org/derby/docs/10.9/getstart/tgsrunningsysinfo.html

thanks,

bryan


RE: DriverManager.getConnection error with JDK 7

Posted by john miltone <mi...@gmail.com>.
And sysinfo -cp : 

C:\Program Files (x86)\Java\jdk1.7.0_10\db\lib>java -jar derbyrun.jar
sysinfo -cp

TROUVE DANS LE CHEMIN DE CLASSES :

   BibliothÞque de moteur intÚgrÚ Derby (derby.jar)
   file:/C:/Program Files (x86)/Java/jdk1.7.0_10/db/lib/derby.jar


   BibliothÞque de moteur intÚgrÚ Derby (derby.jar)
   file:/C:/Program Files (x86)/Java/jdk1.7.0_10/db/lib/derby.jar


   BibliothÞque Derby Network Server (derbynet.jar)
   file:/C:/Program Files (x86)/Java/jdk1.7.0_10/db/lib/derbynet.jar


   BibliothÞques Derby Client (derbyclient.jar)
   file:/C:/Program Files (x86)/Java/jdk1.7.0_10/db/lib/derbyclient.jar


   BibliothÞque d'outils Derby (derbytools.jar)
   file:/C:/Program Files (x86)/Java/jdk1.7.0_10/db/lib/derbytools.jar


REUSSITE : Toutes les classes associÚes Ó Derby ont ÚtÚ trouvÚes dans le
chemin
de classes. (in English it say GOOD : all the associated class Derby it find
in classpath.)



Re: DriverManager.getConnection error with JDK 7

Posted by Bryan Pendleton <bp...@gmail.com>.
>> I caught SQLException and he said that : "No suitable driver found for
>> jdbc:derby:MoneyBack1;create=true;user=miltone;password=password"
>
> So your classloader can't find the derby driver. Have you checked that derby.jar is on your classpath?

The sysinfo tool is useful for diagnosing classpath problems like these:

http://db.apache.org/derby/docs/10.9/getstart/tgsrunningsysinfo.html

thanks,

bryan


Re: DriverManager.getConnection error with JDK 7

Posted by John English <jo...@gmail.com>.
On 23/02/2013 17:47, john miltone wrote:
> I caught SQLException and he said that : "No suitable driver found for
> jdbc:derby:MoneyBack1;create=true;user=miltone;password=password"

So your classloader can't find the derby driver. Have you checked that derby.jar 
is on your classpath?
-- 
John English

RE: DriverManager.getConnection error with JDK 7

Posted by john miltone <mi...@gmail.com>.
Hi John English and thank you for help.

I caught SQLException and he said that : "No suitable driver found for
jdbc:derby:MoneyBack1;create=true;user=miltone;password=password"

I have corrected the comma in my string for create table in Derby but this
error coming back. However I created database in Derby with ij tool with
this command :"connect 'jdbc:derby:MoneyBack1;create=true';
I have inserted value in table and try access those value with select
statement. All is good in derby ij.

My derby path is in jdk 7 db directory.

In my code I tested lot with different connection string but always the same
error hereabove.

Like as :
- String connectionURL = "jdbc:derby:" + dbName + ";create=true;user=" +
user + ";password=" + password ;
- String connectionURL2 = "jdbc:derby:" + dbName + ";create=true;user=" +
user;
- String connectionURL3 = "jdbc:derby:" + dbName + ";user=" + user;
- String connectionURL4 = "jdbc:derby:" + dbName;


-----Message d'origine-----
De : John English [mailto:john.foreign@gmail.com] 
Envoyé : samedi 23 février 2013 14:50
À : derby-user@db.apache.org
Objet : Re: DriverManager.getConnection error with JDK 7

On 23/02/2013 13:21, john miltone wrote:
>          String connectionURL = "jdbc:derby:" + dbName + 
> ";create=true;user=" + user + ";password=" + password ;
>              Connection connexion = 
> DriverManager.getConnection(connectionURL);

Oops, replied too hastily... didn't notice this:

> DriverManager.getConnection throw a exeception always.

Difficult to say unless you provide details of the error message for the
exception. Does the connectionURL work if you connect with IJ? Is the dbname
a relative or absolute directory name? If it's relative, are you in the
correct current directory when you try and connect?

HTH,
--
John English


Re: DriverManager.getConnection error with JDK 7

Posted by John English <jo...@gmail.com>.
On 23/02/2013 13:21, john miltone wrote:
>          String connectionURL = "jdbc:derby:" + dbName + ";create=true;user=" +
> user + ";password=" + password ;
>              Connection connexion = DriverManager.getConnection(connectionURL);

Oops, replied too hastily... didn't notice this:

> DriverManager.getConnection throw a exeception always.

Difficult to say unless you provide details of the error message for the 
exception. Does the connectionURL work if you connect with IJ? Is the dbname a 
relative or absolute directory name? If it's relative, are you in the correct 
current directory when you try and connect?

HTH,
-- 
John English