Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class DbOperations {
- static void addClient(String name, String surname) {
- Connection conn = null;
- try {
- conn = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/products_ex?useSSL=false",
- "root",
- "coderslab"
- );
- String sql = "INSERT INTO clients(name, surname) VALUES(?, ?)";
- PreparedStatement ps = conn.prepareStatement(sql);
- ps.setString(1, name);
- ps.setString(2, surname);
- ps.executeUpdate();
- conn.close();
- } catch(SQLException e) {
- e.printStackTrace();
- } finally {
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment