一般来说是因为你在一个ResultSet里面多次访问同一个结果字段或者没有按照表中的顺序访问结果字段。例如你的表为:
personal:
name char(20)
birthdate date
你使用:
rs.getString("name");
rs.getString("name");//对name的两次访问
或者:
rs.getDate("birthdate");
rs.getName("name");//顺序错误,应该按照表的定义顺序
这两种情况都会出现你的错误。
personal:
name char(20)
birthdate date
你使用:
rs.getString("name");
rs.getString("name");//对name的两次访问
或者:
rs.getDate("birthdate");
rs.getName("name");//顺序错误,应该按照表的定义顺序
这两种情况都会出现你的错误。
我的程序代码是这样。
import java.io.*;
import java.sql.*;
public class aa
{
public static void main(String args[]) throws InstantiationException,IllegalAccessException{
Connection dbCon;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println("ok");
dbCon=DriverManager.getConnection("jdbc:odbc:demo","","");
System.out.println("ok");
ResultSet rs;
Statement stmt;
StringBuffer qry=new StringBuffer(1024);
System.out.println("connect");stmt=dbCon.createStatement();rs=stmt.executeQuery("select * from aa");
System.out.println(rs.getString("1"));//错误就在这一行,最后会显示} catch (ClassNotFoundException e) {
System.out.println("driver not found");
return;
}
catch(SQLException e) {System.out.println("error connect");///最后会显示这几行请问是什么原因??System.out.println("\n*****SQLException caught**\n");
while(e!=null){
System.out.println("SQLState:"+e.getSQLState());
System.out.println("Message:"+e.getMessage());
System.out.println("Vendor:"+e.getErrorCode());
e=e.getNextException();
System.out.println("ok");}
return;
}
}
}
getString(0);
getString(1);
...
可是我用APPLET连接数据库时出现No suitable driver,是什么意思。