Answer the question
In order to leave comments, you need to log in
How to enter data into MySQL DB from TextField in java?
Good!
I'm trying to figure out how to work with a MySQL database. So, there is a TextField txtName field
statement.execute("INSERT INTO deftab (name ) VALUE (txtName.getText().toString)");
Answer the question
In order to leave comments, you need to log in
Use PreparedStatement
....
private static final String INSERT = "INSERT INTO deftab (name ) VALUE (?)";
....
public void insert(String name) {
try (Connection connection = DBConnectionPool.getConnection();
PreparedStatement ps = connection.prepareStatement(INSERT_NEWS)) {
ps.setString(1, name);
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question