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
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
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
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
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.fore...@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
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
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