Guest User

Untitled

a guest
Sep 1st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Cannot detect error in the following jdbc code
  2. package p1;
  3.  
  4.  
  5.  
  6. import java.sql.*;
  7.  
  8. public class jdbcDemo
  9.  
  10. {
  11.  
  12. public static void main(String args[])
  13. { int id = 0;
  14. try
  15. { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  16. Connection con = DriverManager.getConnection("jdbc:odbc:loginDSN");
  17. Connection con1 = DriverManager.getConnection("jdbc:odbc:loginDSN");
  18. Statement stat = con.createStatement();
  19. System.out.println("got connection");
  20. ResultSet rs = stat.executeQuery("Select max(UID) from mytable");
  21. while(rs.next())
  22. { id=rs.getInt(1);
  23. }
  24. id++;
  25. System.out.println(id);
  26. PreparedStatement ps = con1.prepareStatement("Insert into mytable(UID,Username,Password) values(?,?,?)");
  27. ps.setInt(1,id);
  28. ps.setString(2,"abhi");
  29. ps.setString(3,"bindra");
  30.  
  31.  
  32. ps.executeUpdate();
  33.  
  34. }
  35. catch(Exception e)
  36. {
  37.  
  38. e.printStackTrace();
  39. }
  40.  
  41.  
  42.  
  43. }
  44. }
  45.  
  46. ps.setInt(1, id + 1);
Add Comment
Please, Sign In to add comment