snoopy
snoopy

Reputation: 121

Why does MySQL database access require a forward slash in the server url?

I've been learning about databases access using Oracle and MySQL and found this interesting difference.

 String dbURL1 = "jdbc:oracle:@serverName:port:database";

verses

 String dbURL1 = "jdbc:mysql://serverName:port:/database";

Why the slash? If I don't provide the slash for MySQL, compiler is unable to determine a suitable driver. However, for Oracle, if I do provide a slash, the compiler also produces an error.

Upvotes: 0

Views: 878

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726669

The format of connection string in JDBC is not mandated by the standard. Each DB driver is free to decide on its own format, based on the preferences of the designers. Moreover, when multiple drivers exist for the same RDBMS, the format for connection strings to the same database may be different.

According to the MySQL reference manual, MySQL uses the following format for its connection string:

MySQL (MM.MySQL Driver)
jdbc:mysql://<HOST>:<PORT>/<DB>
org.gjt.mm.mysql.Driver

Oracle thin client, on the other hand, uses this format:

Oracle Thin
jdbc:oracle:thin:@<HOST>:<PORT>:<SID>
oracle.jdbc.driver.OracleDriver

As you can see, slash / is part of the required syntax for MySql, but it is not part of the syntax for Oracle.

Upvotes: 0

tstark81
tstark81

Reputation: 488

The URL format is defined by the Driver.

For MySQL you can check the full URL format here.

Upvotes: 1

Related Questions