Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. package bl;
  2.  
  3. import org.apache.commons.dbcp2.BasicDataSource;
  4.  
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8. import java.sql.Connection;
  9. import java.sql.DatabaseMetaData;
  10. import java.sql.DriverManager;
  11. import java.sql.SQLException;
  12. import java.util.Properties;
  13. /**
  14. * Created by glady on 30.06.2017.
  15. */
  16. public class Util
  17. {
  18.  
  19. private String URL = "jdbc:sqlserver://test-db-prod;instanceName=JCAPS;database=db_jdbc_tutorial"; // ;user=xxx;password=xxx";
  20. private String USERNAME = "test";
  21. private String PASSWORD = "test";
  22. private String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
  23.  
  24. public Connection getConnection() {
  25. Connection connection = null;
  26. try {
  27. Class.forName(DRIVER);
  28. connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  29. System.out.println("Connection ok");
  30. } catch (Exception e) {
  31. System.out.println("Error: " + e.getMessage());
  32. }
  33. return connection;
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement