Can not issue data manipulation statements with executeQuery().
importjava.awt.GridLayout;importjava.sql.Connection;importjava.sql.Driver;importjava....
import java.awt.GridLayout;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class UserRegisterFrame extends JFrame {
private JTextField username = new JTextField();
private JTextField password = new JTextField();
private JButton btn = new JButton("注册");
public UserRegisterFrame() {
setLayout(new GridLayout(0,2));
getContentPane().add(new JLabel("用户名:"));
getContentPane().add(username);
getContentPane().add(new JLabel("密码:"));
getContentPane().add(password);
getContentPane().add(btn);
setSize(170,200);
setVisible(true);
}
public static void main(String[] args) {
new UserRegisterFrame();
try {
Class.forName(Driver.class.getName());
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "root", "123");
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("insert into UserRegister (UserRegister.username,UserRegister.userpassword) values (username,password)");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我是想向数据库里面查入数据的,但是貌似有错误的说,错误在哪里? 展开
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class UserRegisterFrame extends JFrame {
private JTextField username = new JTextField();
private JTextField password = new JTextField();
private JButton btn = new JButton("注册");
public UserRegisterFrame() {
setLayout(new GridLayout(0,2));
getContentPane().add(new JLabel("用户名:"));
getContentPane().add(username);
getContentPane().add(new JLabel("密码:"));
getContentPane().add(password);
getContentPane().add(btn);
setSize(170,200);
setVisible(true);
}
public static void main(String[] args) {
new UserRegisterFrame();
try {
Class.forName(Driver.class.getName());
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "root", "123");
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("insert into UserRegister (UserRegister.username,UserRegister.userpassword) values (username,password)");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我是想向数据库里面查入数据的,但是貌似有错误的说,错误在哪里? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询