www.pudn.com > 2007419349385.rar > MySqlUnit.java
/*
* MySqlUnit.java
*
* Created on 2001年5月18日, 上午10:49
*/
package zc.face;
import java.io.*;
import java.sql.*;
/**
*
* @author Administrator
* @version
*/
class MySqlUnit {
/** Creates new MySqlUnit */
public static String printMetaData(ResultSet rs) throws SQLException
{
ResultSetMetaData md=rs.getMetaData();
int colCount=md.getColumnCount();
String colLabel[]=new String[colCount+1];
int colDisplaySize[]=new int[colCount+1];
String colTypeName[]=new String[colCount+1];
System.out.println("database colCount="+colCount);
StringBuffer sb=new StringBuffer();
for(int i=1;i<=colCount;i++){
colLabel[i]=md.getColumnLabel(i);
colDisplaySize[i]=md.getColumnDisplaySize(i);
colTypeName[i]=md.getColumnTypeName(i);
sb.append("Label:"+colLabel[i]+"DisplaySize:"+colDisplaySize[i]+"TypeName:"+colTypeName[i]+"\r\n");
}
return sb.toString();
}
public static String printResultSet(ResultSet rs) throws IOException,SQLException
{
ResultSetMetaData md=rs.getMetaData();
int colCount=md.getColumnCount();
String colLabel[]=new String[colCount+1];
for(int i=1;i<=colCount;i++)
colLabel[i]=md.getColumnLabel(i);
StringBuffer sb=new StringBuffer();
while(rs.next()){
for(int i=1;i<=colCount;i++)
sb.append(colLabel[i]+":"+rs.getObject(i)+" ");
sb.append("\r\n");
}
//if(!rs.next( ))
// System.out.println("查询成功");
// else
// System.out.println("查询失败");
return sb.toString( );
}
}