Scala JDBC connectivity for common databases
When working with a database system via JDBC, the
following information is required for making connection to the database:
- Driver class name: is name of the class that implements java.sql.Driver interface. The JDBC’s driver manager needs to load this class in order to work with the database driver.
- Database URL: a string that contains information about the database to connect to and other configuration properties. This string has its own format and is varied among different databases.
MySQL
Driver class name: com.mysql.jdbc.Driver
Format of database URL: jdbc:mysql://[host][,failoverhost...][:port]/[database]
Examples:
jdbc:mysql://localhost:3306/db
jdbc:mysql://localhost:3306/db?user=manma&password=secret
SQL Server
Driver
class name: com.microsoft.sqlserver.jdbc.SQLServerDriver
Format of
database URL: jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
See more
information about SQL Server connection properties.
Examples:
jdbc:sqlserver://localhost\\sqlexpress;user=sa;password=secret
Oracle
Driver
class name: oracle.jdbc.OracleDriver
Format of
database URL:
jdbc:oracle:<drivertype>:@<database>
jdbc:oracle:<drivertype>:<user>/<password>@<database>
where
drivertype can be thin, oci.
Examples:
jdbc:oracle:thin:@localhost:1521:
SampleDB
jdbc:oracle:oci:@localhost:1521:
SampleDB
jdbc:oracle:oci:root/secret@hoststring>
PostgreSQL
Driver
class name: org.postgresql.Driver
Format of
database URL:
jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database
See more
information about Postgre’s
connection parameters.
Examples:
jdbc:postgresql:Sampledb
jdbc:postgresql://localhost/Sampledb
jdbc:postgresql://localhost:5432/Sampledb
The port number the server
is listening on. Defaults to the PostgreSQL™ standard port number (5432)
//Code example
var Url = "jdbc:postgresql://localhost/SampleDB";
var username = "manma";
var password = "secret";
Connection conn = DriverManager.getConnection(Url, username, password);
No comments:
Post a Comment