当前位置: 技术问答>java相关
编译程序时出现[Message][ODBC 驱动程序 管理器]非法的描述器索引。是什么问题??
来源: 互联网 发布时间:2015-02-08
本文导语: 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=Driver...
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;
}
}
}
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;
}
}
}
|
System.out.println(rs.getString("1"));改为:
System.out.println(rs.getString(1));
System.out.println(rs.getString(1));