Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package config;
- //
- //import java.sql.Connection;
- //import java.sql.DriverManager;
- //
- //public class DB {
- // final String hostname = "localhost";
- // final String database = "room";
- // final String username = "root";
- // final String password = "mysql";
- // final String url = "jdbc:mysql://"+hostname+"/"+database+"?characterEncoding=UTF-8";
- // final String driver = "com.mysql.jdbc.Driver";
- //
- // public Connection getConnection(){
- // try {
- // Class.forName("com.mysql.jdbc.Driver");
- // return DriverManager.getConnection(this.url, this.username, this.password);
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // return null;
- // }
- //
- //}// END CLASS
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- //package config;
- //
- //import com.mysql.jdbc.Connection;
- //
- //import controller.Main;
- //
- //import java.sql.*;
- //import java.util.*;
- //
- //
- //public class DB {
- // public Connection getConnection(){
- // try {
- // Class.forName("com.mysql.jdbc.Driver");
- // String user = "root";
- // String pass = "mysql";
- // String url = "jdbc:mysql://localhost:3306/MemberTT&T?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull";
- // return (Connection) DriverManager.getConnection(url, user, pass);
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- //
- // return null;
- // }
- //
- //
- //
- //}
- package config;
- import java.sql.Connection;
- import java.sql.DriverManager;
- public class DB {
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- getConnection();
- }
- public static Connection getConnection() throws Exception{
- try {
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://127.0.0.1:3306/room";
- String username = "root";
- String password = "mysql";
- Class.forName(driver);
- Connection conn = DriverManager.getConnection(url, username, password);
- System.out.println("connection success");
- return conn;
- } catch (Exception e) {
- // TODO: handle exception
- System.out.println(e);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement