У меня есть следующий класс, но я не уверен, как включить аутентификацию и настроить пользователей при создании.:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class DerbyCreateAndConnect
{
public static void main(String[] args) {
String dbName = "test7",
user = "rss",
password = "westerly";
boolean create = true;
Connection conn1 = createAndConnect(dbName, user, password, create);
Connection conn2 = connectOnly(dbName, "abc", "xyz");
}
public static Connection createAndConnect(String dbName, String user,String password, boolean create) {
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", user);
connectionProps.put("password", password);
String URL = "jdbc:" + "derby" + ":" + dbName + ";create = " + create + ";" + connectionProps;
try{
conn = DriverManager.getConnection(URL);
}catch(SQLException e){
System.out.println(e);
return conn;
}
System.out.println("Created and connected to database " + dbName);
return conn;
}
public static Connection connectOnly(String dbName, String user,String password) {
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", user);
connectionProps.put("password", password);
String URL = "jdbc:" + "derby" + ":" + dbName + ";" + connectionProps;
try{
conn = DriverManager.getConnection(URL);
}catch(SQLException e){
System.out.println(e);
return conn;
}
System.out.println("Connected to database " + dbName);
return conn;
}
}