-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.java
More file actions
63 lines (54 loc) · 1.69 KB
/
Copy pathTable.java
File metadata and controls
63 lines (54 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package Reports;
import Utilz.Printer;
import java.sql.ResultSet;
import java.sql.SQLException;
import static Utilz.Printer.printLineToMonitor;
import static Utilz.Printer.printRowToMonitor;
public class Table {
private String [][] matrix ;
/*
* Конструктор копирует результаты запроса в двумерный массив
* */
public Table(ResultSet resultSet) {
if (resultSet == null) return;
int q=0;
try {
while(resultSet.next()){
q++;
}
matrix=new String[q][resultSet.getMetaData().getColumnCount()];
resultSet.beforeFirst();
int rownum=0;
while (resultSet.next()) {
for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
matrix[rownum][i]=resultSet.getString(i+1);
}
rownum++;
}
resultSet.beforeFirst();
}catch (SQLException e) {
Printer.printLog(e);
}
}
public void transposeTable (){
String [][]rotatedMatrix = new String [matrix[0].length][matrix.length];
for (int i=0;i<matrix.length;i++){
for (int j=0;j<matrix[0].length;j++){
rotatedMatrix[j][i]=matrix[i][j];
}
}
matrix =rotatedMatrix;
}
public void printMatrix (){
if (matrix==null) return;
for (int i=0;i<matrix.length;i++){
for (int j=0;j<matrix[0].length;j++){
printLineToMonitor(matrix[i][j] + "; ");
}
printRowToMonitor("");
}
}
public String[][] getMatrix() {
return matrix;
}
}