Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class Main2 {
- private static final String INSERT_INTO_MOVIES = "INSERT INTO movies (id,name,description,rating) VALUES(?, ?, ?, ?)";
- public static void main(String[] args) {
- try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/cinemas_ex", "root",
- "coderslab"); PreparedStatement prepIns = connection.prepareStatement(INSERT_INTO_MOVIES);) {
- prepIns.setInt(1, 0);
- prepIns.setString(2, "Gwiezdne wojny");
- prepIns.setString(3, "Latajo po kosmosie");
- prepIns.setDouble(4, 400);
- prepIns.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement