×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Java
Posted by: Minh Pham
Added: Oct 18, 2015 5:28 PM
Modified: Nov 26, 2015 4:15 PM
Views: 16
Tags: jdbc
Connect Database throws JDBC
  1. public class Conn_JDBC {
  2.     Connection conn;
  3.     Connection Connect_JDBC(){
  4.         String host = "";
  5.         String port = "";
  6. // String port = : + port's number, if using default port, bypass this.
  7.         String dtbName = "";
  8.         String url = "jdbc:sqlserver://" + host + port + ";databaseName=" + dtbName;
  9.         String user = "";
  10.         String pass = "";
  11.         try {
  12.             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  13.             conn = DriverManager.getConnection(url,user,pass);
  14.         } catch (ClassNotFoundException | SQLException ex) {
  15.             Logger.getLogger(Conn_JDBC.class.getName()).log(Level.SEVERE, null, ex);
  16.         }
  17.         return conn;
  18.     }
  19. }