Getting an SQL exception while updating database

Viewed 32

I have a program that is taking two variables from another class and updating the database. To clarify more, I'm getting Book_ID and member_ID from another class and updating a database (library_mgmt) table (librarymember) but for some reason I'm getting SQL exception.

public class Updatememberbook {
    
    String b_id,m_id;
    String books[] = new String[5];
    public Updatememberbook(String book, int member_id){
        
        try{
            b_id =book;
            m_id= String.valueOf(member_id);//I have tried it in both integer and string format but its still giving same exception
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/library_mgmt", "root", "");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select * from Librarymember where Member_ID=" + m_id);
             
            
            
            while(rs.next()){
                for(int i=0;i<5;i++){
                books[i]=rs.getString(i+5);
            }
            }
            
            books[2]="hello";
            for(int j=0;j<5;j++){
                if(books[j].equals("hello")){
                    System.out.println("books here");
                }
                
            }
        }catch(ClassNotFoundException a){
            System.out.print("Class not found");
                }
        catch(SQLException e){
            System.out.print("SQL exception occured");
        }
        
    }
    
}

This is the desc of my database, the one at the bottom

0 Answers
Related