Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbtienda;
- import java.sql.SQLException;
- import java.sql.DriverManager;
- import java.sql.*;
- public class DBtienda {
- /**
- * @param args the command line arguments
- */
- public static Connection getConnection() {
- Connection connection = null;
- String dbName = "tienda";
- String user = "conexion";
- String pass = "3312";
- try {
- //Class.forName("com.microsoft.sqlserver.jbdc.SQLServerDriver");
- //String connectionDB = "jbdc:sqlserver://localhost\SQLEXPRESS;database="
- String connectionDB = "jbdc:sqlserver://LAPTOP-2V4ND64M\SQLEXPRESS;database="
- //+ dbName + ";user = " + user + ";password = " + pass + ";";
- + dbName + ";integratedSecurity=true;";
- connection = DriverManager.getConnection(connectionDB);
- }
- /*catch(Exception e) {
- System.out.println("Error: " + e.getMessage());
- }*/
- catch(SQLException e) {
- System.out.println("Error: " + e.getMessage());
- }
- catch(Exception e) {
- System.out.println("Error: " + e.getMessage());
- }
- return connection;
- }
- public static void main(String[] args) {
- if(DBtienda.getConnection() != null)
- System.out.println("Conexión exitosa!");
- }
- }
Add Comment
Please, Sign In to add comment