我实际上是在android应用中的数据库上工作(使用android studio)。我坚持这个错误说:
java.lang.NoSuchMethodError: No virtual method group(Ljava/lang/String;)Ljava/lang/String; in class Ljava/util/regex/Matcher; or its super classes (declaration of 'java.util.regex.Matcher' appears in /system/framework/core-libart.jar)
所以,问题是,我的代码可以编译,我可以编译所有内容,但是当我执行此部分时,它将关闭我的应用程序。由于Java / android studio中的DB是我的新手,所以我将为您提供所有技巧。
老实说,我不明白我该怎么做...
这是我使用并在代码中调用的类:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MySQLConnector {
private static final String url = "jdbc:mysql://localhost:3306/mydb";
private static final String user = "root";
private static final String password = "password";
private Connection con;
private Statement stmt;
private ResultSet rs;
public MySQLConnector() throws SQLException {
try {
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
void sendUpdate(String req) throws SQLException {
stmt.executeUpdate(req);
System.out.println("Command executed");
}
public void sendRequest(String req) throws SQLException {
rs = stmt.executeQuery(req);
System.out.println("Command executed");
}
}
这是我的代码中的一个使用示例:
public class Check extends AppCompatActivity {
private Button finApp ;
private Intent intent;
private String sessionID;
private MySQLConnector connector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check);
intent = getIntent();
sessionID = intent.getStringExtra("SessionID");
System.out.println("oncreatebutton");
finApp=findViewById(R.id.button);
try {
connector = new MySQLConnector();
connector.sendRequest("Select * from users");
} catch (SQLException e) {
e.printStackTrace();
}
finApp.setOnClickListener(v -> {
try {
connector.sendUpdate("INSERT INTO users (first_name,last_name," +
"date_created,is_admin,num_points) VALUES('name','lastname',now(),0,6)");
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("test");
System.out.println("Session id is :" + sessionID);
finish();
});
}
}
connector = new MySQLConnector();
connector.sendRequest("Select * from users");
是失败的人
非常感谢任何尝试提供帮助的人。