数据库里的表有4个字段 但当用rs.getstring(3)时程序就提示连接数据库失败
我把代码贴出来
String sex=new String();
String age=new String();
String id=new String();
String name=new String();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
// TODO: handle exception
}
try {
con=DriverManager.getConnection("jdbc:odbc:redsun","","");
sql=con.createStatement();
rs=sql.executeQuery("select * FROM haoma");
while(rs.next())
{
if(haoma.equals(rs.getString(1)))
{
i++;
sex=rs.getString(3);
age=rs.getString(4);
//id=rs.getString(1);
//name=rs.getString(4);
Connection conn = MyDataSource.getInstance().getConnection();
String sql = "select * from t_mc where nid = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, nid);
rs = pstmt.executeQuery();
if (rs.next()) {
int id = rs.getInt("nid");
String sname = rs.getString("sname");
String sdescription = rs.getString("SDESCRIPTION");
double nprice = rs.getDouble("NPRICE");
String simg = rs.getString("SIMG");
String smctag = rs.getString("SMCTAG"); // 是否缺货
Date dcdate = new Date(rs.getTimestamp("DCDATE").getTime());
int nmaxid = rs.getInt("NMAXID");
int nminid = rs.getInt("NMINID");
McBean mcBean = new McBean();
mcBean.setNid(id);
mcBean.setSname(sname);
mcBean.setSdescription(sdescription);
mcBean.setNprice(nprice);
mcBean.setSimg(simg);
mcBean.setSmctag(smctag);
mcBean.setDcdate(dcdate);
mcBean.setNmaxid(nmaxid);
mcBean.setNminid(nminid);
return mcBean;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
free(rs, pstmt, conn);
}