java的报错java.lang.ArrayIndexOutOfBoundsException:麻烦给看一下
//E.classimportjavax.swing.*;importjava.awt.*;importjava.awt.Event.*;publicclassE{pub...
//E.class
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
public class E {
public static void main(String args[]){
JTable table;
Query query;
query=new Query();
query.setDatasourceName("MyData");
query.setTableName("ReaderMessage");
Object a[][]=query.getRecord();
int m=a[0].length; //错误在此处
String b[]=new String[m];
for(int i=0;i<m;i++)
b[i]="字段个数"+(i+1);
table=new JTable(a,b);
JFrame frame=new JFrame();
frame.add(new JScrollPane(table));
frame.setVisible(true);
frame.setBounds(20, 30, 300, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
//Query.class
由于代码量很大,超过字数限制,只发关键的
import java.sql.*;
import javax.swing.JOptionPane;
public class Query {
Object a[][];
public Query(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
}
}
public Object [][] getRecord(){
Connection con;
Statement sql;
ResultSet rs;
try{
String uri="jdbc:odbc:"
con=DriverManager.getConnection(uri,"","");
DatabaseMetaData metadata =con.getMetaData();
ResultSet rs1=metadata.getColumns(null , null, tableName, null);
int 字段个数=0;
while(rs1.next()){
字段个数++;
}
int n=getAmount();
a=new Object[n][字段个数];
sql=con.prepareStatement("select * from"+tableName);
rs=sql.executeQuery(SQL);
int m=0;
while(rs.next()){
for(int k=1;k<=字段个数;k++){
a[m][k-1]=rs.getString(k);
}
m++;
}
con.close();
}
catch(SQLException e){
}
return a;
}
给看看怎么改 展开
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
public class E {
public static void main(String args[]){
JTable table;
Query query;
query=new Query();
query.setDatasourceName("MyData");
query.setTableName("ReaderMessage");
Object a[][]=query.getRecord();
int m=a[0].length; //错误在此处
String b[]=new String[m];
for(int i=0;i<m;i++)
b[i]="字段个数"+(i+1);
table=new JTable(a,b);
JFrame frame=new JFrame();
frame.add(new JScrollPane(table));
frame.setVisible(true);
frame.setBounds(20, 30, 300, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
//Query.class
由于代码量很大,超过字数限制,只发关键的
import java.sql.*;
import javax.swing.JOptionPane;
public class Query {
Object a[][];
public Query(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
}
}
public Object [][] getRecord(){
Connection con;
Statement sql;
ResultSet rs;
try{
String uri="jdbc:odbc:"
con=DriverManager.getConnection(uri,"","");
DatabaseMetaData metadata =con.getMetaData();
ResultSet rs1=metadata.getColumns(null , null, tableName, null);
int 字段个数=0;
while(rs1.next()){
字段个数++;
}
int n=getAmount();
a=new Object[n][字段个数];
sql=con.prepareStatement("select * from"+tableName);
rs=sql.executeQuery(SQL);
int m=0;
while(rs.next()){
for(int k=1;k<=字段个数;k++){
a[m][k-1]=rs.getString(k);
}
m++;
}
con.close();
}
catch(SQLException e){
}
return a;
}
给看看怎么改 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询