Results 1 to 16 of 16
- 10-30-2012, 07:46 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 6
- Rep Power
- 0
DataBase Exception: No Suitable driver found
I have recently switched from C# to Java that why I am very new to java programming. I am trying to write program to learn database connections in java but the I am getting following exceptions while executing my program.
No suitable driver found for jdbc:derby://localhost:1727/dtbs
I am using NetBeans IDE.Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaconsole; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * * @author Prince */ public class JavaConsole { /** * @param args the command line arguments */ public static void main(String[] args) { String host="jdbc:derby://localhost:1727/dtbs"; String user="root"; String password="root"; try{ Connection cnn=DriverManager.getConnection(host,user,password); System.out.println("Connection Established Successfully!"); } catch(SQLException se){ System.out.println(se.getMessage()); } } }
- 10-30-2012, 07:51 PM #2
Re: DataBase Exception: No Suitable driver found
I don't use NetBeans, so I'm not sure if it's installed by default, but you probably have to download and install the Derby JDBC. A quick Google found this page: Derby JDBC driver
- 10-31-2012, 12:02 AM #3
Re: DataBase Exception: No Suitable driver found
Toll is correct - no DB connectors come by default. Grab the jar file Tolls mentions, and add it to the Library section of the project properties. This references the libs you need for building and runtime. If you wish to deploy your app somewhere, you will need to bundle the jdbc and any other libs you use with the jar.
- 10-31-2012, 07:30 AM #4
Member
- Join Date
- Oct 2012
- Posts
- 6
- Rep Power
- 0
Re: DataBase Exception: No Suitable driver found
NetBeans service browser show a data base (or data source as in C#) tree containing my database 'dtbs'. And the driver subtree contains a node named "MySQL Connector (J Driver)". Also in the NetBeans's plugin dialog box contains a plugin for JDB. So it seems that the base IDE it self contains the driver but still I did What you told to me. I downloaded the latest derby driver and included the jar file as well as the complete folder in the project properties but the result is same Exception.
- 10-31-2012, 10:01 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: DataBase Exception: No Suitable driver found
That's Netbeans, not your project.
Your project needs the driver as well.Please do not ask for code as refusal often offends.
- 10-31-2012, 06:42 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 6
- Rep Power
- 0
- 10-31-2012, 06:45 PM #7
Re: DataBase Exception: No Suitable driver found
I think the Derby driver is called derbyclient.jar, not derby.jar. See if you've got a file like that to include.
- 10-31-2012, 07:12 PM #8
Member
- Join Date
- Oct 2012
- Posts
- 6
- Rep Power
- 0
Re: DataBase Exception: No Suitable driver found
Yeah I think I am a step forward now! here is a new exception encountered!
java.net.ConnectException : Error connecting to server localhost on port 1727 with message Connection refused: connect.
- 10-31-2012, 07:39 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: DataBase Exception: No Suitable driver found
A DriverManager doesn't know where to look for jdbc drivers; those drivers have to register themselves at the manager; do something like this before you ask the DriverManager to hand you over a driver:
where <XXX> is "Embedded" or "Client" depending on your needs.Java Code:Class.forName("org.apache.derby.jdbc.<XXX>Driver");
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-31-2012, 07:44 PM #10
Member
- Join Date
- Oct 2012
- Posts
- 6
- Rep Power
- 0
Re: DataBase Exception: No Suitable driver found
Sorry! I dont understand what you want to say. Can you please explain this in a bit detail. Actually I am new to java.
- 10-31-2012, 08:09 PM #11
Re: DataBase Exception: No Suitable driver found
With that last error message, it seems the driver is working at least. One thing I noticed though: In your screenshot, the port is 1527. The error message says 1727. Make sure you're not using the wrong port.
- 11-01-2012, 05:47 AM #12
Member
- Join Date
- Oct 2012
- Posts
- 6
- Rep Power
- 0
Re: DataBase Exception: No Suitable driver found
Yes that was my mistake! But Now I got the same error with the same port i.e. 1527.
- 11-01-2012, 09:51 AM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
- 11-01-2012, 10:51 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: DataBase Exception: No Suitable driver found
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-01-2012, 11:58 AM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: DataBase Exception: No Suitable driver found
From the DriverManager API:
"
The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver.
"
It basically trawls the classpath.Please do not ask for code as refusal often offends.
- 11-01-2012, 01:09 PM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Connecting to Database - No Suitable Driver Found
By Humphrey Bogart in forum New To JavaReplies: 3Last Post: 10-09-2012, 09:59 AM -
MySQL: No suitable driver found.
By Onra in forum JavaServer Pages (JSP) and JSTLReplies: 8Last Post: 12-15-2011, 02:41 PM -
No suitable driver found
By chinna in forum New To JavaReplies: 3Last Post: 11-30-2011, 01:17 PM -
No suitable driver found exception error
By Crazy Caveman in forum NetworkingReplies: 1Last Post: 09-01-2010, 12:03 AM -
No suitable driver found
By geekchick in forum New To JavaReplies: 2Last Post: 08-25-2010, 12:12 AM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks