Test.java的代码
import java.sql.SQLException;
public class Test {
public static void main(String[] args)throws Exception{
// TODO Auto-generated method stub
Datebase date = new Datebase("root","123456");;
date.show();
date.insert("tom","30422","123456");
}
}
Userdata.java的代码
import java.sql.Connection;
import java.util.ArrayList;
public class Userdata {
private String username;
private String userId;
private String password;
public Userdata(String username,String userId,String password) {
this.username = username;
this.userId = userId;
this.password = password;
}
public String getUsername() {
return username;
}
public String getUserId() {
return userId;
}
public String getPassword() {
return password;
}
}
Datebase.java的代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Datebase {
Connection coon = null;
public Datebase(String username,String password )throws Exception {
Class.forName("com.mysql.jdbc.Driver");
this.coon=DriverManager.getConnection("jdbc:mysql://localhost:3306/stu",username,password);
}
public void show() {
System.out.println(this.coon);
}
public void insert(String username,String userId,String password)throws SQLException {
PreparedStatement pre=coon.prepareStatement("insert into userdata value(?,?,?)");
pre.setString(1, username);
pre.setString(2, userId);
pre.setString(3, password);
pre.executeQuery();
}
public void delete(String userId) {
}
public Userdata getuser() {
return null;
}
public ArrayList<Userdata> getAlluser(){
return null;
}
public void close()throws Exception {
coon.close();
}
public Userdata check(String username,String userId ) {
return null;
}
}
一运行就会显示这段话“Exception in thread "main" java.sql.SQLException: Can not issue data manipulation statements with executeQuery().”该怎么解决