private final static String databaseName="Map";
private final static String url = "jdbc:sqlserver://localhost;database="+databaseName;
private final static String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final static String userName = "sa";
private final static String password = "password123";
public static Connection getConnection() throws Exception {
if (connection != null)
return connection;
else {
try {
Class.forName(driver).newInstance();
connection = DriverManager.getConnection(url, userName, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
}
private final static String url = "jdbc:sqlserver://localhost;database="+databaseName;
private final static String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final static String userName = "sa";
private final static String password = "password123";
public static Connection getConnection() throws Exception {
if (connection != null)
return connection;
else {
try {
Class.forName(driver).newInstance();
connection = DriverManager.getConnection(url, userName, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
}
0 comments: