Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package base;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- * Created by sanchitalekh on 12/03/2017.
- */
- public class DBConnection {
- String server;
- String port;
- String dbname;
- String username;
- String password;
- public DBConnection(String server, String port, String dbname, String username, String password){
- this.server = server;
- this.port = port;
- this.dbname = dbname;
- this.username = username;
- this.password = password;
- try {
- Connection conn =
- DriverManager.getConnection("jdbc:mysql://" + server + ":" + port + "/" + dbname + "?" +
- "user=" + username + "&password=" + password);
- if(conn != null){
- System.out.println("Conn Successful!");
- }
- }
- catch (SQLException ex) {
- // handle any errors
- ex.printStackTrace();
- }
- }
- public static void main(String[] args) {
- DBConnection db = new DBConnection("localhost","8889","test","test","test");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement