主题:[讨论]bean访问microsoft access问题
请问:在用bean访问access时,总出现“BuyerBean.getLogonTimes():【ODBC Microsoft Access Driver】参数不足,期待是1”的错误,编译都通过了的,真实奇怪!该bean如下:
/* * BuyerBean.Java 7.3.2004
*Copyright(c) 2004,2005 by cuug llp.
*本Bean中有两个set方法和两个get方法;
*setMembetID()-对BuyerBean中的memberID属性进行赋值;
*setPwd()-对BuyerBean中的pwd属性进行赋值;
*getLogontimes()-取该会员登录的次数
*getMemberName()-获得该会员的真实姓名,用于显示欢迎信息。
*main()方法用于将Bean作为一个Application进行测试时使用,正式发布时可以删除。
**/
package cuug;
import java.sql.*;
public class BuyerBean
{
private String memberID=null;
private String memberName=null;
private String pwd=null;
private int logontimes=-1;
private static String strDBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; //JDBC 驱动
private static String strDBUrl="jdbc:odbc:bookstore"; //数据源
private Connection conn=null; //连接
private ResultSet rs=null; //结果集
public BuyerBean()
{
//加载JDBC-ODBC驱动
try
{
Class.forName(strDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("BuyerBean():"+e.getMessage());
}
}
//获得登录的次数,登录的会员的名字也在该方法时获得
public int getLogontimes()
{
String strSql=null;
try
{
conn=DriverManager.getConnection(strDBUrl);
Statement stmt=conn.createStatement();
strSql="select logonTimes,membername from buyerInfo where memberID='"+memberID+"' and pwd='"+pwd+"'";
rs=stmt.executeQuery(strSql);
while(rs.next())
{
//登录的次数
logontimes=rs.getInt("logonTimes");
//会员姓名
memberName=rs.getString("membername");
}
rs.close();
if(logontimes!=-1)
{
strSql="Update buyerInfo set logonTimes=logonTimes+1 where memberID='"+memberID+"'";
stmt.executeUpdate(strSql);
}
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.err.println("BuyerBean.getLogontimes():"+e.getMessage());
}
return logontimes;
}
//设置memberID的属性
public void setMemberID(String ID)
{
this.memberID=ID;
}
//设置pwd属性
public void setPwd(String password)
{
this.pwd=password;
}
//获得该会员的真实姓名,必须在取该会员登录的次数之后赋予正确的值
public String getMemberName()
{
return memberName;
}
//测试Bean中的各方法是否能够正常工作
public static void main(String args[])
{
BuyerBean buyer=new BuyerBean();
buyer.setMemberID("1");
buyer.setPwd("皑皑");
System.out.println(buyer.getLogontimes());
System.out.println(buyer.getMemberName());
}
}
/* * BuyerBean.Java 7.3.2004
*Copyright(c) 2004,2005 by cuug llp.
*本Bean中有两个set方法和两个get方法;
*setMembetID()-对BuyerBean中的memberID属性进行赋值;
*setPwd()-对BuyerBean中的pwd属性进行赋值;
*getLogontimes()-取该会员登录的次数
*getMemberName()-获得该会员的真实姓名,用于显示欢迎信息。
*main()方法用于将Bean作为一个Application进行测试时使用,正式发布时可以删除。
**/
package cuug;
import java.sql.*;
public class BuyerBean
{
private String memberID=null;
private String memberName=null;
private String pwd=null;
private int logontimes=-1;
private static String strDBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; //JDBC 驱动
private static String strDBUrl="jdbc:odbc:bookstore"; //数据源
private Connection conn=null; //连接
private ResultSet rs=null; //结果集
public BuyerBean()
{
//加载JDBC-ODBC驱动
try
{
Class.forName(strDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("BuyerBean():"+e.getMessage());
}
}
//获得登录的次数,登录的会员的名字也在该方法时获得
public int getLogontimes()
{
String strSql=null;
try
{
conn=DriverManager.getConnection(strDBUrl);
Statement stmt=conn.createStatement();
strSql="select logonTimes,membername from buyerInfo where memberID='"+memberID+"' and pwd='"+pwd+"'";
rs=stmt.executeQuery(strSql);
while(rs.next())
{
//登录的次数
logontimes=rs.getInt("logonTimes");
//会员姓名
memberName=rs.getString("membername");
}
rs.close();
if(logontimes!=-1)
{
strSql="Update buyerInfo set logonTimes=logonTimes+1 where memberID='"+memberID+"'";
stmt.executeUpdate(strSql);
}
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.err.println("BuyerBean.getLogontimes():"+e.getMessage());
}
return logontimes;
}
//设置memberID的属性
public void setMemberID(String ID)
{
this.memberID=ID;
}
//设置pwd属性
public void setPwd(String password)
{
this.pwd=password;
}
//获得该会员的真实姓名,必须在取该会员登录的次数之后赋予正确的值
public String getMemberName()
{
return memberName;
}
//测试Bean中的各方法是否能够正常工作
public static void main(String args[])
{
BuyerBean buyer=new BuyerBean();
buyer.setMemberID("1");
buyer.setPwd("皑皑");
System.out.println(buyer.getLogontimes());
System.out.println(buyer.getMemberName());
}
}