读书人

只能取得主键的值其他字段都是null,

发布时间: 2011-12-23 23:32:01 作者: rapoo

只能取得主键的值,其他字段都是null,数据库中都是有值的,可能是什么原因阿,在线等
String querySql1 = "select sid,area,co,tel,fax,email from ServiceRepresentatives " ;
// + " order by area ";

Connection conn = null ;
dbConn dbconn = new dbConn();
try
{
conn = dbconn.getConnection() ;

// Statement stmt = conn.createStatement();
// ResultSet V_rst = stmt.executeQuery(querySql1);
PreparedStatement pstat = conn.prepareStatement( querySql1 ) ;
ResultSet V_rst = pstat.executeQuery() ;

while( V_rst.next() )
{
RepresentativeForm V_RepresentativeForm = new RepresentativeForm();

System.out.println( V_rst.getString(1) );
System.out.println( V_rst.getString(2 ) );
System.out.println( V_rst.getString(3 ) );
System.out.println( V_rst.getString(4 ) );
System.out.println( V_rst.getString(5 ) );
System.out.println( V_rst.getString(6 ) );

//V_RepresentativeForm.setSID ( V_rst.getString( "sid " ) );
//V_RepresentativeForm.setArea ( V_rst.getString( "area " ) );


//V_RepresentativeForm.setCo ( V_rst.getString( "co " ) );
//V_RepresentativeForm.setTel ( V_rst.getString( "tel " ) );
//V_RepresentativeForm.setFax ( V_rst.getString( "fax " ) );
//V_RepresentativeForm.setEmail ( V_rst.getString( "email " ) );

V_ArrayList.add( V_RepresentativeForm );
}


}
catch (Exception ex)
{
System.out.println( "Query查询数据库错误! ");
ex.printStackTrace();
}
finally
{
dbconn.closeCon();
}

用的是sqlserver数据库,web服务器是resin 2.0

[解决办法]
“select sid,area,co,tel,fax,email from ServiceRepresentatives”

数据库的查询分析器里运行一下看看是否真的有值


[解决办法]
看看其它字段的类型是否都是字串型
[解决办法]
数据库里的值没有commit ? 以前我经常出这个问题.

读书人网 >Java Web开发

热点推荐