Java.sql.SQLException:Column ' class ' not found. Exception not found column

Source: Internet
Author: User

1 /**when dealing with an object, there is either one in RS or one without it. 2  * @param<T>3  */4  Public classBeanhandler<t>ImplementsResultsethandler<t> {5     PrivateClass<t>type;6      PublicBeanhandler (class<t>type) {7          This. Type =type;8     }9     /**the rs->t TTen      */ One      PublicT handle (ResultSet RS)throwsSQLException { A         //1 Creating an object of type T using reflection technology -         //type->user.class -         //type.newinstance () "is equivalent to" User user = new user (); theT t =NULL; -         Try { -t =type.newinstance (); -             if(Rs.next ()) { +                 //User.class->beaninfo Info -BeanInfo info =introspector.getbeaninfo (type); +                 //gets the object (attribute type, property name, Setxxx, and GetXXX) for all properties from info APropertydescriptor[] PDS =info.getpropertydescriptors (); at                 //iterating through an array -                  for(intI =0;i<pds.length;i++){ -                     //gets the current property of the current T object corresponding to the Setxxx (..) -Method MT =Pds[i].getwritemethod (); -                     //gets the name of the current property such as: Username -String pname =pds[i].getname (); in                     //t.setxxx (rs.getstring ("attribute name")) - Mt.invoke (t, Rs.getobject (pname)); to                 } +             } -             returnT; the}Catch(Exception e) { * e.printstacktrace (); $         } Panax Notoginseng          -         returnT; the     } +}

Test, throws an exception:
Java.sql.SQLException:Column ' class ' not found.
The cause of the error is:
Rs.getobject ("class");
A column with the name class does not exist in the table user table of the database.
We have no class at all in the user class, why does this column appear?
The reason is that when user does not specify a parent class, someone is a subclass of object, inherits the class attribute from the object class, and therefore
There is a problem with the class column that does not exist.
Workaround:

1 Try {2mt.invoke (t, Rs.getobject (pname)); 3 }catch  (SQLException e) {4continue; 5 }

Java.sql.SQLException:Column ' class ' not found. Exception not found column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.