jdbcCreating a database connection


Syntax

  • DB_URL = "jdbc:DBMS://DB_HOST:DB_PORT/DB_NAME"

  • DBMS: Data Base Driver Manager, this can be any DBMS (mysql, oracle, postgresql, sqlite, ...), exemple of mysql: "com.mysql.jdbc.Driver"

  • DB_HOST: your database base host, the IP adress of your database exemple : 10.6.0.1, the default is localhost or 127.0.0.1

  • DB_PORT: Database port, every DBMS has a defeaut port exemple mysql=3306, postegesql=5432

  • DB_NAME: the name of your Database

  • To connect you should to obtains a reference to the class object,

  • Class.forName(DRIVER);

  • And to connect to database, you need to create a connection

  • java.sql.Connection con = DriverManager.getConnection(DB_URL, DB_USER_NAME, DB_PASSWORD);

  • DB_USER_NAME : the username of your databse

  • DB_PASSWORD : the password of your database