No suitable driver found for jdbc:mariadb (Netbeans) - java

I'm using the mariadb-java-client-1.5.7.jar connector for MariaDB, and it does not work.
Here's the connection code:
public DataAccess() throws SQLException, ClassNotFoundException {
this.driver = "org.mariadb.jdbc.Driver";
this.host = "jdbc:mariadb://localhost/bluebank";
this.user = "root";
this.password = "";
Class.forName(this.driver);
this.conn = DriverManager.getConnection(this.host, this.user, this.password);
}
I get:
java.sql.SQLException: No suitable driver found for jdbc:mariadb://localhost/bluebank
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at DAO.DataAccess.<init>(DataAccess.java:31)
Apart from adding as an external jar to the libraries, I've added it as a driver to the databases in (Services) in Netbeans. Also, if I remove the Class.forName(), it doesn't work as well.

Had something similar today. Worked in Eclipse, did not with pure Java.
For me it was important to have
Class.forName ("org.mariadb.jdbc.Driver");
to make it work everywhere.

You forgot the port number of your database :
this.host = "jdbc:mariadb://localhost:port_number/bluebank";
Make sure that your db connector jar, exist in the your jar libraries: https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/
You can learn more here :
Connect to MariaDB from Java application in NetBeans on Linux (Mageia)
Hope this can help you

replace mariadb in the url with mysql:
I had this Problem myself: the solution was quite simple... MariaDB is basically still MySQL. In the Url you are using to connect to the Database (jdbc:mariadb://localhost:3306) you can therefore just use jdbc:mysql://localhost:3306 <- i just replaced mariadb with mysql. It is still running on a mariadb server but it works so dont change it ;)
Still i dont know why none of the other solutions have worked but at least it is a solution

Related

intellij com.mysql.jdbc.Driver issues, tried multiple methods

I've been searching for more than a day now on this simple problem. This is my first time using Intellij/Android Studio as I come from using Eclipse. The issue I'm having is that the project can't find my driver. I've done this multiple times, usually you would just have to make sure that the mysql-connector.jar is referenced/added to the project. However, Intellij is not so simple in this regard. First, I am using the free version and not the ultimate, so I do not have the database tools option but luckily, there is a database navigator plugin. I add it and set my connections. I use the built-in driver as shown
and my code is the following:
private static Connection connection = null;
private static String driver = "com.mysql.jdbc.Driver";
private static String url, user, password = "";
private static String server = "localhost";
public LoginDataSource() {
System.out.println("Connecting to database...");
setDatabase(server);
try {
Class.forName(driver); // <-- fails here
connection = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
Error due to
W/System.err: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
W/System.err: at java.lang.Class.classForName(Native Method)
I keep looking and some say to add the connector jar as a maven dependency. I do that as shown:
and I add it here too
I run the application again and still same error. So next I go back to database navigator and edit the driver to external and select the regular driver as shown:
I run the application again and still the same error... I am at a lost. I don't know what to do, and it would be really great if someone could tell me.
This is my external libraries if it helps, the mysql connector is not shown here
I tried multiple ways and I know there are VERY similar threads on this but believe me, I have tried and I still can't figure it out on my own. Any help would be greatly appreciated. Thank you.
I will try to help. First, remove your previous MySQL driver dependencies, to start from scratch. Then, you need to declare a dependency in your "build.gradle" file:
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
After you add this line to the script, refresh the gradle dependencies.
Then, try to load the driver again, but note that com.mysql.jdbc.Driver is deprecated now, use com.mysql.cj.jdbc.Driver.
I will answer your questions if this small instruction fails.

Can't connect to MySQL database: No suitable driver found

I'm having some troubles with java and jdbc.
In particular, while my code perfectly works in a NetBeans project, when i try to execute it on a terminal or on my ubuntu vps (which is where i need it to work) i always get this exception:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/quakes
First thing first: yes, i'm adding the jdbc .jar to the execute command and the compile command; Yes, i've even tried to add
Class.forName("com.mysql.jdbc.Driver");,
but I always get a ClassNotFoundException: com.mysql.jdbc.Driver exception
The .jar i'm using is the exact same that i use in the NetBeans project, so i know i have the right thing, and even downloading it again from the official site won't change a thing.
Yes, the database exists, and the result doesn't change if i try to connect to another db.
I also tried switching to postgresql (yes, i didn't forget to change the url), but to no avail, it still can't find the driver.
With this, i'm guessing that the actual error is in the compile/execute commands, but even them should be ok:
javac *.java <-cp mysql-connector-java-5.1.41-bin.jar > (the <> parenthesis means that i tried compiling with and without specifying the classpath);
java TAW -cp mysql-connector-java-5.1.41-bin.jar,
In case you want to see it, here's the method that tries to connect to the database:
public Connection getConnection() throws SQLException {
if (conn == null) {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+
this.dbname,this.user,this.pass);
}
return conn;
}
Does anyone have any idea on why this happens?
You need to put the classpath option for java before the name of your main class, otherwise it is regarded as program arguments:
java -cp mysql-connector-java-5.1.41-bin.jar;. TAW
You can use this method step by step to create connetion.
it is an example connectivity:
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/feedback?"
+ "user=sqluser&password=sqluserpw");

Netbeans JDBC Error "Unable to find suitable driver" after JDK update

I recently upgraded my jdk from 6 to 8 when I installed Eclispe for Android. Now, in NetBeans when I try to right click on the node for the database and select connect, I get the following error:
"Unable to connect. Cannot establish a connection to jdbc:derby://localhost 1527:/Animal using org.apache.derby.jdbc.ClientDriver (Unable to find a suitable driver)."
So far, I have tried uninstalling Eclipse and reinstalling Netbeans and that didn't work. I'm not getting any errors in my code aside from a popup that says the project is missing resources. Could someone please provide instructions on how to solve this issue? I've looked on the NetBeans' website and on this forum and there doesn't seem to be a clear procedure for resolving this.
If that's not a typo on your part your JDBC URL is malformed:
jdbc:derby://localhost 1527:/Animal
That's what I copied from your question. However, the correct URL would look like
jdbc:derby://localhost:1527/Animal
With the colon before the port, not after.
At Netbeans already states that this driver was tried but failed I'm quite sure it's got nothing to do with your driver setup. But if you want todouble check:
Here's a tutorial on how to add and enable oracle thin driver. I'd think it will work the same way for derby drivers.
I solved it in the following way:
The driver that you use to connect to the database may have deleted it or changed your address. So that:
You must put it back in the address that was indicated in the databases driver>
Drivers> (driver you use to connect)
Indicate the new address where you are
The error is in the path you are specifying in the driver or in the connection.
I had the same problem when trying to connect MySQL server to NetbeansIDE. Turns out the jdbc connector was an old version. You can read about the MySQL connector versions here. Either
download the latest version of MySQL connector or
add a new driver.
My problem was solved by adding a new driver.

Conflict between Netbeans IDE 8.0 and UCanAccess?

I have to define a new Driver in the Netbeans "Services" Tab
Services->Databases->Drivers->new Driver...
because I want use the "Entity Classes from Database"-Wizard in context with UCanAccess.
1st step: "new Driver" does work (only declaration ;-) )
Driver File(s): f:\WorkspaceNetbeans\MSAccessDB\lib\UCanAccess-2.0.4-bin\ucanaccess-2.0.4.jar
Driver Class: net.ucanaccess.jdbc.UcanaccessDriver
Name:msaccess
2nd step: "Connect using..."
JDBC URL: jdbc:ucanaccess://F:/WorkspaceNetbeans/MSAccessDB/data/Datenbank2.accdb
"User Name" and "Password" leave blank
The "Test Connection"-Button results in Error Message:
Cannot establish a connection to
jdbc:ucanaccess://F:\WorkspaceNetbeans\MSAccessDB\data\Datenbank2.accdb using
net.ucanaccess.jdbc.UcanaccessDriver (Could not initialize class
net.ucanaccess.jdbc.UcanaccessDriver)
I've got the newest ucanaccess from http://ucanaccess.sourceforge.net/site.html
ucanaccess-2.0.4.jar, commons-lang-2.6.jar, commons-logging-1.0.4.jar, hsqldb.jar, jackcess-2.0.3.jar in the Netbeans Classpath.
The old fashion way to connect via jdbc to ucanaccess works fine.
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String connectString = "jdbc:ucanaccess://" + "f:/WorkspaceNetbeans/MSAccessDB/data/Datenbank2.accdb";
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn = DriverManager.getConnection(connectString, "", "");
conn.createStatement().execute("CREATE TABLE example1 (id COUNTER PRIMARY KEY,descr text(400), number numeric(12,3), date0 datetime) ");
}
The same connection string also works fine make DBeaver able to connect to the MSAccess db.
My set up:
Windows 7 Professional 64 bit
Microsoft Office 2013
NetBeans IDE 8.0
Java 1.8
The problem is similar to: "Conflict between JT400 and UCanAccess?" Conflict between JT400 and UCanAccess?
but the answers there don't help with my problem.
Any ideas to solve my problem?
UCanAccess 2.0.4.1 has been released, now you can configure UCanAccess as NetBeans service.
As explained in the UCanAccess web site (tab 'jdbc client tools') you have to:
-in the field Driver File(s), add ucanaccess.jar and all dependencies. I've upgraded the commons-logging in the UCanAccess distribution to the 1.1.1, so you can use that jar with NetBeans8.
-use the following pattern for the jdbc url:
jdbc:ucanaccess://;showschema=true
Showschema connection property must be setted to true.
I was wrong, it wasn't a tricky task but...
To establish the connection you have to list in the Driver File(s) :
ucanaccess-2.0.4.jar,
commons-lang-2.6.jar,
hsqldb.jar,
jackcess-2.0.3.jar
AND
a different version of commons-logging that you can find it in NetBeans:
NetBeans 8.0\ide\modules\org-apache-commons-logging.jar (the commons-logging in the UCanAccess distribution is in conflict with that used by NetBeans)
But unfortunatly, after establishing the connection, you won't be able to execute queries through this IDE, because of a trivial bug in the UcanaccessDatabaseMetadata which hasn't effect with the other IDE jdbc clients I tested (Openoffice, Libreoffice, DBeaver, Squirrel, SQLeo and so on) .
So, to do this, you have to wait some days (I think I'll post a patched Ucanaccess 2.0.4.1 next week). Also, I'll add a note about UCanAccess configuration as NetBeans service in the UCanAccess web site.

java.sql.SQLException: No suitable driver found for jdbc:sqlserver [duplicate]

This question already has answers here:
The infamous java.sql.SQLException: No suitable driver found
(21 answers)
Closed 3 years ago.
I am working on a web application where I am creating MSSQLSERVER 2008
database dynamically.
But it's giving me
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;databaseName=master
My code is:
String dbName = "db1";
try {
String url = "jdbc:sqlserver://localhost:1433;databaseName=master";
Connection connection = DriverManager.getConnection(
url,
"sa",
"roshan14121987");
Statement statement = connection.createStatement();
String sqlquery = "CREATE Database \"" + dbName + "\"; ";
statement.executeUpdate(sqlquery);
statement.close();
connection.close();
} catch(Exception e) {
e.printStackTrace();
}
I have added sqljdbc4.jar in lib. I have tried it on both NetBeans (with GlassFish and Tomcat Server) and Eclipse IDE(Tomcat Server).
On the other hand I have tried this with simple desktop application, it's working fine on both IDEs. With sqljdbc4.jar added in lib.
Before calling DriverManager.getConnection() you will have to load the SQLServer JDBC driver. You can do Class.forName("xxxx"); where xxxx is the appropriate driver class (fully qualified name with package prefix).
EDIT: Do this Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); to load the driver. Refer MSDN link for more.
Is sqljdbc4.jar in your war file under WEB-INF/lib. This is the alternate location to $CATALINA_HOME/lib and recommended to keep your web application self-contained. Further, if you should ever need to change servers, you need only drop the war into your webapps directory.
You might also need a Class.forName([database class]).newInstance, but that isn't necessary using a JDBC 4.0 driver. Good luck and if you have further problems, do leave a comment.
The error happen in the runtime on Tomcat Server,right? I think you need to make sure your sqljdbc4.jar deploy the in the Server.

Categories