Java Connection database and simple operation see my previous essay:http://www.cnblogs.com/meitian/p/5036332.html first, the number of rows and columns to get the results of the queryquery result is ResultSet object
this. executequery (sql_temp);
To view the number of columns:
int column_count=selectresult.getmetadata (). getColumnCount ();
GetMetaData () returns all column informationGetMetaData (). getColumnName (i): I pass the column int index to get the name of the column To view the number of rows:
int row_count=selectresult.getrow ();
Second, print the results of the query and corresponding valuesso if you want to print the value of the query, you can query the query result column number, and then loop to print, the code is as follows
This. con =drivermanager.getconnection (URL, user, password); This. stmt =con.createstatement (); ResultSet Selectresult= This. stmt.executequery (SQL);intColumn_count =selectresult.getmetadata (). getColumnCount ();intSize = 0; while(Selectresult.next () && Size < 10) {String Selectresult_single= ""; for(inti = 1; I <= Column_count; i++) {String ColumnName=selectresult.getmetadata (). getColumnName (i); String Columnvalue=selectresult.getstring (i); Selectresult_single= Selectresult_single + ColumnName + "=" + Columnvalue + ""; } size= size + 1;}
Description: Because I don't want to print all of the results, I've added a maximum number of prints in the while
Java gets the number of columns and rows of the database query results, printing the query results