Connect To mysql://localhost - Java java.sql

Java examples for java.sql:MySQL

Description

Connect To mysql://localhost

Demo Code


//package com.java2s;
import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
    public static Connection ConnectToDB(Connection conn) {
        //TODO: move db address to resources
        String url = "jdbc:mysql://localhost/valeriy_ubiserv_test";
        try {//from  w w w .j  ava 2 s.  c  o m
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url, "root", "root");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;
    }
}

Related Tutorials