Guest User

arta

a guest
Jan 9th, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1.  
  2. import java.sql.*;
  3.  
  4. public class jdbc1{
  5.  
  6. public static void main(String[] args) throws SQLException {
  7.  
  8. Connection conn= null;
  9.  
  10. String url= "jdbc:postgresql://172.16.1.99:5432/chinook";
  11. conn = DriverManager.getConnection(url, "ut99999", "pw99999");
  12.  
  13. Statement st=conn.createStatement();
  14.  
  15. // int numero_riga_inserita=st.executeUpdate("insert into artist values(4001, 'forlin')");
  16.  
  17. // inserire un nuovo artista con id massimo +1 di quelli esistenti
  18.  
  19. ResultSet rs=st.executeQuery("select max(artist_id) from artist");
  20.  
  21. rs.next();
  22. int max=rs.getInt(1);
  23. max++;
  24.  
  25. int max_id=st.executeUpdate("insert into artist values(" + max + ",'arta')");
  26.  
  27.  
  28.  
  29.  
  30. }
  31.  
  32. }
Add Comment
Please, Sign In to add comment