×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: juan marin
Added: Aug 27, 2016 7:38 PM
Views: 7
Tags: database
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. public class DBUtil {
  7. private static final String oraUser="hr";
  8. private static final String oraPwd ="hr";
  9. private static final String mySqlUser = "root";
  10. private static final String mySqlPwd = "root";
  11. private static final String oraCS = "jdbc:oracle:thin:@localhost:1521:xe";
  12. private static final String mySQLCS = "jdbc:mysql://localhost:3306/world";
  13.  
  14. public static Connection getConnection(DBType dbType) throws SQLException {
  15.         switch (dbType) {
  16.         case ORADB:
  17.                 return DriverManager.getConnection(oraCS, oraUser, oraPwd);
  18.         case MYSQLDB:
  19.                 return DriverManager.getConnection(mySQLCS, mySqlUser, mySqlPwd);
  20.  
  21.         default:
  22.                 return null;
  23.         }
  24. }
  25.  
  26. public static void showErrorMessage(SQLException e){
  27.         System.err.println("Error :" + e.getMessage());
  28.         System.err.println("Error Code :" + e.getErrorCode());
  29. }
  30. }