Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cannot detect error in the following jdbc code
- package p1;
- import java.sql.*;
- public class jdbcDemo
- {
- public static void main(String args[])
- { int id = 0;
- try
- { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con = DriverManager.getConnection("jdbc:odbc:loginDSN");
- Connection con1 = DriverManager.getConnection("jdbc:odbc:loginDSN");
- Statement stat = con.createStatement();
- System.out.println("got connection");
- ResultSet rs = stat.executeQuery("Select max(UID) from mytable");
- while(rs.next())
- { id=rs.getInt(1);
- }
- id++;
- System.out.println(id);
- PreparedStatement ps = con1.prepareStatement("Insert into mytable(UID,Username,Password) values(?,?,?)");
- ps.setInt(1,id);
- ps.setString(2,"abhi");
- ps.setString(3,"bindra");
- ps.executeUpdate();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- ps.setInt(1, id + 1);
Add Comment
Please, Sign In to add comment