I have a problem on android studio when I try to make a connection to a mysql database
This is the code:
public Connection getMySqlConnection()
{
/* Declare and initialize a sql Connection variable. */
Connection ret = null;
try
{
/* Register for jdbc driver class. */
Class.forName("com.mysql.cj.jdbc.Driver");
/* Create connection url. */
String mysqlConnUrl = "jdbc:mysql://ip/ristorante?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
/* db user name. */
String mysqlUserName = "guest";
/* db password. */
String mysqlPassword = "guestpass";
/* Get the Connection object. */
ret = DriverManager.getConnection(mysqlConnUrl , mysqlUserName , mysqlPassword );
/* Get related meta data for this mysql server to verify db connect successfully.. */
DatabaseMetaData dbmd = ret.getMetaData();
String dbName = dbmd.getDatabaseProductName();
String dbVersion = dbmd.getDatabaseProductVersion();
String dbUrl = dbmd.getURL();
String userName = dbmd.getUserName();
String driverName = dbmd.getDriverName();
System.out.println("Database Name is " + dbName);
System.out.println("Database Version is " + dbVersion);
System.out.println("Database Connection Url is " + dbUrl);
System.out.println("Database User Name is " + userName);
System.out.println("Database Driver Name is " + driverName);
}catch(Exception ex)
{
ex.printStackTrace();
}finally
{
return ret;
}
}
this is the main error:
W/System.err: java.lang.UnsupportedOperationException
at java.util.regex.Matcher.group(Matcher.java:383)
at com.mysql.cj.conf.ConnectionUrlParser.isConnectionStringSupported(ConnectionUrlParser.java:152)
at com.mysql.cj.conf.ConnectionUrl.acceptsUrl(ConnectionUrl.java:258)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:195)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:219)
at com.example.spara.restaurant.activity_home.getMySqlConnection(activity_home.java:163)
at com.example.spara.restaurant.activity_home.onCreate(activity_home.java:80)
I tried the same code in eclipse java and it worked...
I had tried several times in different ways but without positive results.
so the database connection works. I just cannot find a solution, I hope you can help me.