Advertisement
TermSpar

SQL Add Values

Mar 24th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. import javax.swing.JOptionPane;
  4. public class Session {
  5.     public Session(){
  6.         try{
  7.            
  8.             //CONNECT TO DATABASE
  9.             Connection myConn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root", "admin");
  10.            
  11.             //CREATE STATEMENT
  12.             Statement mySmt = myConn.prepareStatement("UPDATE addTest SET id = id + 1");
  13.            
  14.             //EXECUTE SQL QUERY
  15.             mySmt.executeUpdate("UPDATE addTest SET id = id + 1");
  16.         }catch (Exception exc){
  17.             exc.printStackTrace();
  18.             JOptionPane.showMessageDialog(null, exc.getMessage());
  19.         }
  20.     }
  21.    
  22.     public static void main(String args[]){
  23.         new Session();
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement