我对java不太熟悉,我有一个截止日期很短的项目。让我们进入正题。我有以下课程:
public static void getAllDataDB1() // Catching all the data from "bank1" database
{
try
{
MetaData1 = connection1.getMetaData();
catalogs1 = MetaData1.getCatalogs();
String[] types = {"TABLE"};
resTables1 = MetaData1.getTables(null,null,"%",types);
while (resTables1.next())
{
db1TableName = resTables1.getString("TABLE_NAME");
System.out.println("|=====================================================|");
System.out.println("| CATCHING " +dbName1+"."+db1TableName+ " DATA |");
System.out.println("|=====================================================|");
System.out.println("|=====================================================|");
System.out.println("| THE QUERY IS IN PROGRESS. PLEASE WAIT... |");
System.out.println("|=====================================================|");
resTablesStr1 = statement1.executeQuery("SELECT * FROM "+db1TableName+";");
resColumns1 = resTablesStr1.getMetaData();
db1ColNum = resColumns1.getColumnCount();
db1FirstColName = resColumns1.getColumnName(1);
for (int i=1; i<=db1ColNum; i++)
{
db1FirstColName = resColumns1.getColumnName(1);
db1ColName = resColumns1.getColumnName(i);
System.out.println("| COLUMN: " +db1ColName+ " |");
System.out.println("\n");
resTablesData1 = statement1.executeQuery("SELECT "+db1ColName+" FROM "+db1TableName+" GROUP BY "+db1FirstColName+";");
while (resTablesData1.next())
{
db1RowNum++;
}
columnsArrayDB1 = new String[db1RowNum][db1ColNum];
resTablesData1 = statement1.executeQuery("SELECT "+db1ColName+" FROM "+db1TableName+" GROUP BY "+db1FirstColName+";");
resTablesData1.next();
String rowData = resTablesData1.getString(db1ColName);
for (int j=0; j<db1RowNum; j++)
{
System.out.println();
for (int k=0; k<db1ColNum; k++)
{
columnsArrayDB1[j][k] = rowData;
System.out.println("|-----------------------------------------------------|");
System.out.print("| "+columnsArrayDB1[j][k]+" |"+"\t");
System.out.println("|-----------------------------------------------------|");
//columnsArrayDB1[j][x+1]=columnsArrayDB1[j][x];
}
}
/*while (resTablesData1.next())
{
String rowData = resTablesData1.getString(db1ColName);
for (int j=0; j<db1RowNum; j++)
{
System.out.println(rowData);
//columnsArrayDB1[j] = rowData;
//System.out.print(columnsArrayDB1[j]+" ");
}
System.out.println(rowData);
}*/
}
}
}
catch (SQLException e)
{
System.err.println("Connection Failed! Check output console " + e.getMessage());
System.exit(0);
}
}
我正在尝试从特定数据库中捕获所有数据并将它们作为矩阵样式存储到数组中。我在编译和运行上述代码时收到的结果是这样的:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
| COLUMN: Gender |
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
female female female female female female female female female female female female female female female female female female female female female female
当您意识到我想要这样的结果时:
1 female Mrs.
2 male Mr.
etc... etc...
请告知我应该怎么做,因为我被困在这里寻找电脑......乔治。