Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class ConnectionSqlServer {
  6. private static Connection connection;
  7.  
  8. // win + r : sqlservermanager12.msc pour récupérer l'instance de ssms
  9. private static String url = "jdbc:sqlserver://localhost\\SQLExpress;databasename=FestivalCannes;user=sa;password=sql2014;integratedsecurity=false";
  10. //integradedsecurity=true : permet de se logguer avec l'auth windows, et on ne précise ni user ni psw
  11. public static Connection getConnection() throws SQLException{
  12. if(connection == null){
  13. connection = DriverManager.getConnection(url);
  14. }
  15. return connection;
  16. }
  17.  
  18. public static void Close() throws SQLException{
  19. if(connection != null){
  20. connection.close();
  21. }
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement