In my application I'm using MySQL as the RDMS and I'm trying to connect to the database with the usual classes under java.sql
.
I've a constructor in this class that is responsible for connecting or creating the database which accepts a parameter to specify the database path.
I would like to do some checks on the string passed to this constructor to check if it's a valid URL path. Currently, I'm using the following code, but I'm not sure if there's something that I'm forgetting or if it can be improved, maybe my simply checking using a regular expression.
private boolean isValidDBName(String dbName) {
return dbName != null && !dbName.isEmpty() && dbName.startsWith("jdbc:mysql://") && dbName.endsWith("/");
}