help me java web (Can you guide the solution?) 1)file db DbContext public class DBContext { protected Connection connection; public DBContext() { try { String user = "sa"; String pass = "123456789"; String url = "jdbc:sqlserver://MSI:1433;databaseName=MyOrder"; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); connection = DriverManager.getConnection(url, user, pass); } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(DBContext.class.getName()).log(Level.SEVERE, null, ex); } } } 2)public class DBContext1 { public Connection getConnection()throws Exception { String url = "jdbc:sqlserver://"+serverName+":"+portNumber +";databaseName="+dbName; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); return DriverManager.getConnection(url, userID, password); } private final String serverName = "<>"; private final String dbName = "<>"; private final String portNumber = "<>"; private final String userID = "<>"; private final String password = "<>"; }
help me java web (Can you guide the solution?)
1)file db DbContext
public class DBContext {
protected Connection connection;
public DBContext()
{
try {
String user = "sa";
String pass = "123456789";
String url = "jdbc:sqlserver://MSI:1433;databaseName=MyOrder";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(url, user, pass);
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DBContext.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
2)public class DBContext1 {
public Connection getConnection()throws Exception {
String url = "jdbc:sqlserver://"+serverName+":"+portNumber +";databaseName="+dbName;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
return DriverManager.getConnection(url, userID, password);
}
private final String serverName = "<<server-name>>";
private final String dbName = "<<database-name>>";
private final String portNumber = "<<port-number>>";
private final String userID = "<<user-id>>";
private final String password = "<<password>>";
}
Step by step
Solved in 7 steps with 2 images