Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class MySQLAccess {
- private Connection connect = null;
- private Statement statement = null;
- private PreparedStatement preparedStatement = null;
- private ResultSet resultSet = null;
- public void writeDataBase(Integer ico) throws Exception {
- try {
- // toto načíta MySQL ovládač, každá DB má vlastný ovládač
- Class.forName("com.mysql.jdbc.Driver");
- // Nastavenie spojenia s DB
- connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=8671");
- statement = connect.createStatement();
- preparedStatement = connect.prepareStatement("UPDATE tssu.faktura SET partner = 'áno' WHERE id = ?");
- // Parameters start with 1
- preparedStatement.setInt(1, ico);
- } catch (Exception e) {
- throw e;
- } finally {
- close();
- }
- }
- // You need to close the resultSet
- private void close() {
- try {
- if (resultSet != null) {
- resultSet.close();
- }
- if (statement != null) {
- statement.close();
- }
- if (connect != null) {
- connect.close();
- }
- } catch (Exception e) {
- }
- }
- }
Add Comment
Please, Sign In to add comment