代码样例:https://code.fanruan.com/demo/example/src/release/10.0/src/main/java/com/fr/data/ParamTableDataDemo.java
// 获取数据库连接 driverName和 url 可以换成您需要的
public Connection getConnection() {
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;databaseName=db";
String username = "sa";
String password = "sa1234";
Connection con = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return con;
}