我在jsp页面中用的bean,可以只选需要的
package db;
import java.sql.*;
public class ViewQueryBean {
private DbConnection d ;
private ResultSet rset =null;
public ViewQueryBean() throws SQLException{
d = new DbConnection();
System.out.println("db");
d.openConnection();
}
public ResultSet executeQuery(String query) throws SQLException{
rset = d.exceuteQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException{
d.executeUpdate(query);
}
public void close(){
if(d!=null) d.close();
if (rset != null) {
rset=null;
}
}
public void finalize(){
this.close();}
public int getRowCount(){
try {
this.rset.last();
return this.rset.getRow();
}
catch (SQLException ex) {
return 0;
}
}
public int getColumnCount(){
try {
ResultSetMetaData rsmd = rset.getMetaData();
return rsmd.getColumnCount();
}
catch (SQLException ex) {
return 0;
}
}
public String getString(int index) {
try {
return rset.getString(index);
}
catch (SQLException ex) {
return null;
}
}
public String getString(String columnName){
try {
return rset.getString(columnName);
}
catch (SQLException ex) {
return null;
}}
public String getColumnName(int index){
try {
ResultSetMetaData rsmd = rset.getMetaData();
return rsmd.getColumnLabel(index) != null ? rsmd.getColumnLabel(index) : "";
}
catch (SQLException ex) {
return null;
}
}
public boolean next (){
try {
return rset.next();
}
catch (Exception ex) {
return false;
}
}
public Object getObject(int index) {
try {
return rset.getObject(index);
}
catch (SQLException ex) {
return null;
}
}
public void absolute(int i){
try {
this.rset.absolute(i);
}
catch (SQLException ex) {ex.printStackTrace();
}
}
public ResultSet getResultSet(){
return this.rset;}
}
package db;
import java.sql.*;
public class ViewQueryBean {
private DbConnection d ;
private ResultSet rset =null;
public ViewQueryBean() throws SQLException{
d = new DbConnection();
System.out.println("db");
d.openConnection();
}
public ResultSet executeQuery(String query) throws SQLException{
rset = d.exceuteQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException{
d.executeUpdate(query);
}
public void close(){
if(d!=null) d.close();
if (rset != null) {
rset=null;
}
}
public void finalize(){
this.close();}
public int getRowCount(){
try {
this.rset.last();
return this.rset.getRow();
}
catch (SQLException ex) {
return 0;
}
}
public int getColumnCount(){
try {
ResultSetMetaData rsmd = rset.getMetaData();
return rsmd.getColumnCount();
}
catch (SQLException ex) {
return 0;
}
}
public String getString(int index) {
try {
return rset.getString(index);
}
catch (SQLException ex) {
return null;
}
}
public String getString(String columnName){
try {
return rset.getString(columnName);
}
catch (SQLException ex) {
return null;
}}
public String getColumnName(int index){
try {
ResultSetMetaData rsmd = rset.getMetaData();
return rsmd.getColumnLabel(index) != null ? rsmd.getColumnLabel(index) : "";
}
catch (SQLException ex) {
return null;
}
}
public boolean next (){
try {
return rset.next();
}
catch (Exception ex) {
return false;
}
}
public Object getObject(int index) {
try {
return rset.getObject(index);
}
catch (SQLException ex) {
return null;
}
}
public void absolute(int i){
try {
this.rset.absolute(i);
}
catch (SQLException ex) {ex.printStackTrace();
}
}
public ResultSet getResultSet(){
return this.rset;}
}