0

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.

3
  • 2
    If you're trying to talk to a SQL server, why are you making sure that an Oracle driver is present, and then using a mysql JDBC URL? You should really re-read a tutorial and make sure you understand what each part of the code does - if the right classes are in your classpath, you shouldn't need the Class.forName() call at all these days, but you do need an appropriate JDBC URL for your database. Commented Dec 14, 2015 at 15:56
  • Then what should I use? Commented Dec 14, 2015 at 15:58
  • 1
    Try to search the internet. Google is a good starting point. Commented Dec 14, 2015 at 15:58

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

5 Comments

I got the same error. is my string ok? I don't know what and where i have to write?
You string should be DriverManager.getConnection("jdbc:mysql://localhost:3306/yourdatabase","your_user", "your_password"), so I think corect is something like this "jdbc:mysql://SQLEXPRESS:3306/Test", "win2cng9", "kmim1437", if understand what is your user, server and password
Thank you for helping, and sorry for stupid question( oracle with mysql), but I have to start somewhere ;)
The OP isn't using mysql. They're using SQL Server. Oracle and mysql are both distractions, presumably due to cobbling together code from elsewhere without understanding it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.