Discuss Java.sql.SQLException: No suitable driver in the Java Help forum on Dev Shed. Java.sql.SQLException: No suitable driver Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
both the emdedded driver and the client driver produce the same resulting exception:
Code:
ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
SQLException: java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/COFFEEBREAK
From what I understand, this is a badly formed url issue, but I'm not sure how to fix it. I'm running this on windows xp, using netbeans 5.5 (I've also tried from command line, same result).
I'm pretty sure I have the classpaths and paths set up correctly for Derby, UI followed the instructions on that.
I've googled this for 2 days, and I'm at a loss. Any help would be greatly appreciated!
Posts: 10,135
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
You're right about it being a URL problem (good catch!). My bet is that you're using the embedded driver, rather than the network driver. The URL format for the embedded driver is:
jdbc:derby:databaseName;URLAttributes
Try that instead, and let us know if it works. More information can be found in the Derby QuickStart Guide.
Cheers.
~
__________________ Yawmark
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
Posts: 324
Time spent in forums: 1 Week 2 Days 13 h 3 m 46 sec
Reputation Power: 60
Quote:
Originally Posted by Yawmark
You're right about it being a URL problem (good catch!). My bet is that you're using the embedded driver, rather than the network driver. The URL format for the embedded driver is:
jdbc:derby:databaseName;URLAttributes
Try that instead, and let us know if it works. More information can be found in the Derby QuickStart Guide.
Cheers.
~
thanks for pointing me in the right direction Yawmark. From what I read, having the url as jdbc:derby:dbName will work as long as the database is in the same directory as the class. so thats what I did and it worked! Now I'll read up on the url a bit more.
Posts: 324
Time spent in forums: 1 Week 2 Days 13 h 3 m 46 sec
Reputation Power: 60
Ok, I've been googling how to form the url, but I've had no luck.
As I said, I can get it to work if its in the same directory as the database, but can't seem to form the proper url for the script to look in a different folder structre for the database. Anyone have any insight on this? Its on windows.
Posts: 10,135
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
I missed the ClassNotFoundException the first time! You're using a non-embedded URL along with the embedded driver, but the embedded driver isn't visible to the runtime classpath!
Posts: 324
Time spent in forums: 1 Week 2 Days 13 h 3 m 46 sec
Reputation Power: 60
Thanks Bullet and Yawmark,
I should have stated I changed my code now:
Code:
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc:derby:COFFEEBREAK";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url,
"admin", "admin");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.toString());
}
}
}
[\code]
so, from what I've read, I should have the embedded driver above, and the embedded url format.
now I have more questions though LOL. where can I find out more infomration on emmbedded vs a client driver. And... if my database is in a seperate directory from my java class, how do I format the url?
I tried this
[code]
String url = "jdbc:derby:c:\\DB\\COFFEEBREAK";
but I recieve this message when running:
Code:
ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
SQLException: java.sql.SQLException: No suitable driver found for jdbc:derby:c:\DB\COFFEEBREAK
Yawmark, I think you've given me a clue with "the embedded driver isn't visible to the runtime classpath!" but I'm bnot sure what to do about that.
Sorry for dragging this out, I really appreciate the help!
Posts: 10,135
Time spent in forums: 3 Months 1 Week 4 Days 1 h 22 m 45 sec
Reputation Power: 5052
Quote:
does this look right?
Looks good to me, but please note that if you're running your application from inside an IDE or other framework, your system classpath won't matter much. That's by design. Applications such as Tomcat or Eclipse won't use the system classpath at runtime and depend on their own classloaders.
Posts: 324
Time spent in forums: 1 Week 2 Days 13 h 3 m 46 sec
Reputation Power: 60
Quote:
Originally Posted by Yawmark
but please note that if you're running your application from inside an IDE or other framework, your system classpath won't matter much. That's by design. Applications such as Tomcat or Eclipse won't use the system classpath at runtime and depend on their own classloaders.
~
I've been using Netbeans. However, I've also been using a text editor on the side, and I compiled and ran the class using the text editor version from the cmd prompt, and everything worked!!
So, now I will read up on classloaders in Netbeans, and see if I can get Netbeans to do what I want.
Posts: 1
Time spent in forums: 6 m 27 sec
Reputation Power: 0
Quote:
Originally Posted by bkolts
thanks for pointing me in the right direction Yawmark. From what I read, having the url as jdbc:derby:dbName will work as long as the database is in the same directory as the class. so thats what I did and it worked! Now I'll read up on the url a bit more.
Thank you so much for pointing out that the database in the same directory! I have been grinding on this problem for the last two weeks now, and it's been driving me nuts. Finally got it worked out, and am eternally thankful to you.
Posts: 324
Time spent in forums: 1 Week 2 Days 13 h 3 m 46 sec
Reputation Power: 60
Quote:
Originally Posted by OwlVision
Thank you so much for pointing out that the database in the same directory! I have been grinding on this problem for the last two weeks now, and it's been driving me nuts. Finally got it worked out, and am eternally thankful to you.