-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEnterPoint.java
executable file
·79 lines (73 loc) · 2.3 KB
/
EnterPoint.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class EnterPoint {
public static void main(String[] args){
System.out.println("Connect to database ");
Connection connection=connector.get_connection_to_firebird("","D:/Computer_shop/Program/Delphi7/Server/DataBase/server_data.gdb", 3050, "SYSDBA", "masterkey");
System.out.println("Connection:"+connection);
System.out.println("Get ResultSet ");
ResultSet rs=getResultSet(connection,"select * from people");
System.out.println("Result:");
try{
writeTableToWriterFromResultSet(rs,new PrintWriter(System.out));
}catch(IOException ioex){
System.err.println("IOException: "+ioex.getMessage());
}catch(SQLException sqlex){
System.err.println("IOException: "+sqlex.getMessage());
}
}
/**
* @param rs - ResultSet data
* @param out - for output data
* */
private static void writeTableToWriterFromResultSet(ResultSet rs, Writer out) throws SQLException, IOException{
// âûâåñòè çàãîëîâîê
ResultSetMetaData metaData=rs.getMetaData();
out.write("<table>");
out.write(" <thead>");
out.write("<tr>");
int columnCount=metaData.getColumnCount();
for(int counter=0;counter<columnCount;counter++){
out.write("<th>");
out.write(metaData.getColumnLabel(counter+1));
out.write("</th>");
}
out.write("</tr>");
out.flush();
out.write(" </thead>");
out.write(" <tbody>");
while(rs.next()){
out.write("<tr>");
for(int counter=0;counter<columnCount;counter++){
out.write("<td>");
try{
out.write(rs.getString(counter+1));
}catch(Exception ex){
out.write("");
}
out.write("</td>");
}
out.write("</tr>");
out.flush();
}
out.write(" </tbody>");
out.write("</table>");
metaData.getColumnCount();
// âûâåñòè äàííûå
}
private static ResultSet getResultSet(Connection connection,String query){
ResultSet returnValue=null;
try{
returnValue=connection.createStatement().executeQuery(query);
}catch(SQLException sqle){
System.err.println("getResultSet Exception:"+sqle.getMessage());
}
return returnValue;
}
}