Advertisement
Guest User

Untitled

a guest
May 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. public class Main2 {
  8. private static final String INSERT_INTO_MOVIES = "INSERT INTO movies (id,name,description,rating) VALUES(?, ?, ?, ?)";
  9.  
  10. public static void main(String[] args) {
  11.  
  12. try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/cinemas_ex", "root",
  13. "coderslab"); PreparedStatement prepIns = connection.prepareStatement(INSERT_INTO_MOVIES);) {
  14.  
  15. prepIns.setInt(1, 0);
  16. prepIns.setString(2, "Gwiezdne wojny");
  17. prepIns.setString(3, "Latajo po kosmosie");
  18. prepIns.setDouble(4, 400);
  19.  
  20. prepIns.executeUpdate();
  21. } catch (SQLException e) {
  22. // TODO Auto-generated catch block
  23. e.printStackTrace();
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement