Java Query database column name, output code that needs to be written

Source: Internet
Author: User

Program development Sometimes there are a number of special database tables, this time a binding T data column is more troublesome, you can query the database column name, directly output, you can output columns, add different content output

    /*** This method separates the table names according to the result set of the query, so they are displayed sequentially *@paramtableName database table name *@authorTXF*/     Public voidgetAllUsers (String tableName) {Connection conn=Dbconnection.getconn (); String SQL= "SELECT * from" +tablename+ "where Rownum=1"; PreparedStatement stmt=NULL; ResultSet RS=NULL; String name=""; Try{stmt=conn.preparestatement (SQL); RS=Stmt.executequery (); ResultSetMetaData RSMD=Rs.getmetadata ();  for(intI=1;i<=rsmd.getcolumncount (); i++) {Name=Rsmd.getcolumnname (i); //if (S.get ("Memo") ==null) pstmt.setstring (13, ""); Else Pstmt.setstring (S.get ("Memo"). toString ());System.out.println ("if (S.get (\" "+name.tolowercase () +" \ ") ==null) pstmt.setstring (" +i+ ", \" \ "); else pstmt.setstring ("+i+", S.get (\ "" "+name.tolowercase () +" \ "). toString ());"); //System.out.print (name+ ","); //System.out.print ("?,");               }        } Catch(SQLException e) {e.printstacktrace (); } finally{dbconnection.close (RS,NULL, STMT, conn); }            }

Java Query database column name, output code that needs to be written

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.