java.lang.NoSuchMethodError:没有与JDBC相关的虚拟方法组(Ljava/lang/String;)
我实际上是在android应用程序中处理数据库(使用android studio)。我坚持这个错误说:java.lang.NoSuchMethodError:没有与JDBC相关的虚拟方法组(Ljava/lang/String;),java,android,jdbc,Java,Android,Jdbc,我实际上是在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 i
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();
});
}
}
下面是我的代码中的一个使用示例:
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();
});
}
}
是那些失败的吗
非常感谢所有试图提供帮助的人。从未听说过android中的mysql。我想您可能需要使用SQLite或使用远程连接。它确实工作了一两次,而且我能够从数据库中读取信息。你认为使用SQLite会更容易@RicardoA吗?我不知道你想做什么。如果您只需要处理手机中的信息,最好使用SQLite,否则如果代码正常,您可能就找到了正确的路径。我应该能够在1个发送方和X个接收方之间拥有一个共享数据库。和send应该能够获取“接收方”在同一数据库中发送的数据项。另外,您的评论让我想到了如何使用多台设备获取本地数据库。这可能就是问题所在。似乎您正在使用特定的SDK(或库)。你应该在问题中说明这一点,这样别人就更容易发现问题。