Is general SQL query in Java feasible?
                                        
                    •
                    Java                                    
                If I have a method to create an SQL query, it is as follows:
public List selectTuple() {
   boolean status = true;
   String query = "SELECT ";
   query += getFields() == null ? " * " : " " + getFields() + " ";
   query += " FROM " + tables;
   if ( getSearchClause() != null ) {
       query += " " + getSearchClause();
   }
   query += ";";
   Debug("sql...........caleed selectTuple method,query is : "+ query);
   setQuery(query);
   if ( getPrepared() ) {//If this is a Prepared query,status = setPreparedStatement();
   } else {
      status = setNonPreparedStatement();
   }
   if ( ! status ) {
      Log("[CRITICAL] (.........)..........");
   }
   status = doExecuteQuery();
   if ( ! status ) {
      Log("[CRITICAL] (.........)..........");
   }
   return( getResults() );
}//method selectTuple
However, since this will be used for different tables, fields will have different data types (int, string, date, etc.) So how to iterate such a resultset?
In addition, how do I create such an insert query?
thank you.
Solution
Yes, I think it can be done... You can use GetMetadata () in the resultset to get the number and type of columns, and therefore iterate over the resultset
getMetaData():
ResultSetMetaData class
However, I don't know how to write such a general insert query
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        