I am getting this exception
No suitable driver found for
jdbc:derby://localhost:1527/Test [saad on SAAD]
Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/Test [saad on SAAD]");
Before this
Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/Test [saad on SAAD]", dbusername, dbpassword); // default username = "root" , default password = ""
You have to write this
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
But first of all, you must import the driver jar for apache derby
Related
Iam tryig to connect to a Postgres Database. Iam really new to that and have read a post in the forum. But I didn't manage it.
public void connect() {
//Connection con = null;
try {
Class.forName("org.postgresql.Driver");
Properties props = new Properties();
props.setProperty("user", user);
props.setProperty("password", password);
props.setProperty("ssl","true");
Connection conn = DriverManager.getConnection(url, props);
//String url = "jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true";
//Connection conn = DriverManager.getConnection(url);
System.out.println("Erfolgreich verbunden!");
}
catch (Exception e){
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
}
EDIT:
I updated my Code.
The database is deployed to heroku.
It throws the error:
java.sql.SQLException: No suitable driver found for jdbc:postgres://vuqmbekwlgohkw:******
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)
at com.company.Database.connect(Database.java:20) p
at com.company.Main.start(Main.java:16)
at com.company.Main.main(Main.java:25)
java.sql.SQLException: No suitable driver found for jdbc:postgres://vuqmbekwlgohkw:***************
I believe that your problem is that your connection URL is malformed.
When DriverManager.getConnection throws SQLException, the message includes the exact url value passed to the function. In your case, that looks like jdbc:postgres://vuqmbekwlgohkw:******.
But obviously that is not the URL you are using. You have replaced part of the URL with asterisks. That suggests that you think the format of the URL is:
jdbc:postgres://username:password#host:port/dbname
which seems to be what Heroku provides in the DATABASE_URL environment variable. You are using asterisks to prevent us from seeing the password.
However, it looks like the PostgreSQL JDBC driver does not accept URLs in this format. When I tried, I also got the "No suitable driver" error. According to the documentation, the format of the URL is:
jdbc:postgres://host:port/database
Some parts are optional, but the driver does not appear to support putting the user name or password in the URL.
I was able to connect to an AWS PostgreSQL instance by using the URL format described in the documentation and using the connection properties to set the user name and password.
You said you are new so I'm gonna start with the painfully obvious, do you have the driver on your classpath?
it's a jar you add to your project that you can download from https://jdbc.postgresql.org/
Otherwise I have an example of the url that worked for me, except I was not exactly using jdbc, it was a spring-boot project:
jdbc:postgresql://ec2-174-99-88-88.compute-1.amazonaws.com:5432/asdfasdfsadf?sslmode=require
There is no port number in your commented URL and not all parameters might be supported, like Willis pointed out.
Getting exception in my java code
Exception:
java.sql.SQLException: No suitable driver found for jdbc:ucanaccess:C:\Users\mindurka\Desktop\SeleniumWorkspace\TestCaseSheet\TestCaseSheet.mdb;
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
System.setProperty("DUCANACCESS_HOME","C:/Users/mindurka/Downloads/Selenium3.4/UCanAccess-4.0.2-bin/UCanAccess-4.0.2-bin");
String connURL = "jdbc:ucanaccess:"+TestCaseSheetPath+";";
Connection objAccessCon = DriverManager.getConnection(connURL);
Have included all the five jars in the source folder in my library set
C:\UCanAccess-4.0.2-bin\UCanAccess-4.0.2-bin
I do not understand the reason behind this. Kindly help.
jdbc:ucanaccess:C:\Users\mindurka\Desktop\SeleniumWorkspace\TestCaseSheet\TestCaseSheet.mdb
is not a valid connection URL. It needs to begin with
jdbc:ucanaccess://
followed by the path to the database file.
My Bad.. I missed a double forward slash in the connection string. It should be ...
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
System.setProperty("DUCANACCESS_HOME","C:/Users/mindurka/Downloads
/Selenium3.4/ UCanAccess-4.0.2-bin/UCanAccess-4.0.2-bin");
String connURL = "jdbc:ucanaccess:**//**"+TestCaseSheetPath;
Connection objAccessCon = DriverManager.getConnection(connURL);
Connection objAccessConData = DriverManager.getConnection(connURL1);
Statement objRS = objAccessCon.createStatement();
I need to connect to two different database from my code. First is Hive database and another one is Oracle. For this purpose I need to load two different drivers one for Hive and another for Oracle. Here is what I did:
Class.forName("org.apache.hive.jdbc.HiveDriver");
System.out.println("Driver Found");
Connection connection = DriverManager.getConnection(
"jdbc:hive2://10.8.219.36:10000/default", "lab", "lab");
System.out.println("Connection established");
System.out.println("------------------");
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Found");
Connection connection1 = DriverManager.getConnection(
"jdbc:oracle:thin:#97.253.16.117:1521:NATTDB11",
"CDR_LOADER", "CDR_LOADER");
System.out.println("Connection established");
and when I am running the above code, this is what is got error:
Driver Found
Connection established
------------------
Driver Found
java.lang.IllegalArgumentException: Bad URL format
at org.apache.hive.jdbc.Utils.parseURL(Utils.java:185)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:84)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Demo.main(Demo.java:17)
How do I do this? Thank you in advance.
Try to explicitly register both drivers using:
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
DriverManager.registerDriver (new org.apache.hive.jdbc.HiveDriver());
Then test both Connection types.
Hy!
I really need your help. I'm trying to connect a database to a java program. This is my first time, so I have no idea what i'm doing.
My sql server: Sql server
I want to connect the Test database to the java program.
I tried the following code:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql:WIN2CNG9\\SQLEXPRESS:3306/Test", "win2cng9\\kmim1437", "");
conn.close();
The error:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql:WIN2CNG9\SQLEXPRESS:3306/Test
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at javaapplication42.JavaApplication42.main(JavaApplication42.java:24)
Java Result: 1
What is my mistake?
Thank you for any help.
Class.forName("oracle.jdbc.driver.OracleDriver");
DriverManager.getConnection("jdbc:mysql:
Why your use Oracle driver with mysql database? Use following code:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql:WIN2CNG9\\SQLEXPRESS:3306/Test", "win2cng9\\kmim1437", "");
conn.close();
How can I find out the URL and port for an Oracle database?
Example:
"jdbc:oracle:thin:#host:port:dbName","userName", "password");
Is there an SQL command or log/configuration file I can look at?
With oracle, there is a tnsnames.ora file which defines database addresses. This file is normally found in $ORACLE_HOME/network/admin and is used by oracle clients like sqlplus or Toad. Here is a sample tns entry:
ORA11 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORA11)
)
)
From this entry you can work out that your jdbc connection string would be:
jdbc:oracle:thin:#hostname:1521:ORA11
By reading the documentation which came along with the JDBC driver in question.
In case of the Oracle JDBC thin driver, you can find it here.
Specifying a Database URL, User Name, and Password
The following signature takes the URL, user name, and password as separate parameters:
getConnection(String URL, String user, String password);
Where the URL is of the form:
jdbc:oracle:<drivertype>:#<database>
The following example connects user scott with password tiger to a database with INSTANCE_NAME orcl through port 1521 of host myhost, using the Thin driver.
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#myhost:1521:orcl", "scott", "tiger");
If you want to use the default connection for an OCI driver, specify either:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:scott/tiger#");
or:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:#", "scott", "tiger");
For all JDBC drivers, you can also specify the database with a Oracle Net keyword-value pair. The Oracle Net keyword-value pair substitutes for the TNSNAMES entry. The following example uses the same parameters as the preceding example, but in the keyword-value format:
Connection conn = DriverManager.getConnection
(jdbc:oracle:oci:#MyHostString","scott","tiger");
or:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:#(description=(address=(host= myhost)
(protocol=tcp)(port=1521))(connect_data=(INSTANCE_NAME=orcl)))",
"scott", "tiger");