如何把select sum(字段) as XXX from table中返回的XXX显示在页面?
如何把select sum(字段) as XXX from table中返回的XXX显示在页面,希望能给出代码,先谢谢大家了。
------解决方案--------------------up~~up~~提个和楼主相同类型的问题:
如何完成一个论坛,要求图片能上传,能做缓存,语法高亮显示
--------希望能给出代码,谢谢大家了.
- -!
------解决方案--------------------楼上的是不是应该自己开个帖子???
select sum(字段) as XXX from table 中的XXX 和普通的select a,b,c from table 中的a,b,c一样提取即可。
------解决方案--------------------做个记号
------解决方案--------------------一般XXX都是固定了的,直接写上去,如果要动态取出这个列名,...
下面的代码不知道能不能满足你要求
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import
java.sql.SQLException;
import java.sql.Statement;
public class GetSchemaByResultSet {
public GetSchemaByResultSet() {
super();
}
private static Connection getJdbcConnection(){
Connection con = null;
try{
Class.forName( "oracle.jdbc.driver.OracleDriver ");
String url = "jdbc:oracle:thin:@192.168.0.0:1521:abc ";
con = DriverManager.getConnection(url, "bac ", "abc ");
con.setAutoCommit(false);
} catch(Exception e){
System.out.println(e);
if(con != null){
try{
con.close();
} catch(
SQLException ex){
System.out.println(ex);
}
}
}
return con;
}
public void getSchemaTest() {
Connection con = getJdbcConnection();
try {
Statement st = con.createStatement();
String sql = "select operatorid a from t_operator ";
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData meta=rs.getMetaData();
System.out.println( "meta.getColumnCount() "+meta.getColumnCount());
for(int i=1;i <=meta.getColumnCount();i++){
System.out.println( "===========start=========== "+i);
int columnDisplaySize=meta.getColumnDisplaySize(i);
String columnLabel=meta.getColumnLabel(i);
String columnName=meta.getColumnName(i);
int columnType=meta.getColumnType(i);
String columnTypeName=meta.getColumnTypeName(i);
String tableName=meta.getTableName(i);
String schemaName=meta.getSchemaName(i);
System.out.println( "columnDisplaySize: "+columnDisplaySize);
System.out.println( "columnLabel: "+columnLabel);
System.out.println( "columnName: "+columnName);
System.out.println( "columnType: "+columnType);
System.out.println( "columnTypeName: "+columnTypeName);
System.out.println( "tableName: "+tableName);
System.out.println( "schemaName: "+schemaName);
System.out.println( "===========end=========== ");
}
rs.close();
st.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GetSchemaByResultSet getSchema=new GetSchemaByResultSet();
getSchema.getSchemaTest();
}
}
------解决方案--------------------