-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
176 lines (144 loc) · 5.89 KB
/
Program.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using IBM.Data.Db2;
using System.IO;
using System.Diagnostics;
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Console.WriteLine("Using DB2 .NET provider");
string path = Directory.GetCurrentDirectory();
Console.WriteLine("The current directory is {0}", path);
Console.WriteLine("LD Library path is "+ Environment.GetEnvironmentVariable("LD_LIBRARY_PATH"));
Console.WriteLine(" Switch on the trace \n");
int counter =0;
while (counter < 100000000)
{
counter++;
}
//
string connString=Environment.GetEnvironmentVariable("connectionstring");
DB2Connection conn = new DB2Connection(connString);
conn.Open();
Console.WriteLine("Connection Open");
Console.WriteLine(conn.InternalOperation1());
conn.Close();
Console.WriteLine("Connection Close");
conn.Open();
Console.WriteLine("Connection Open");
conn.Close();
Console.WriteLine("Connection Close");
conn.Open();
Console.WriteLine("Connection Open");
conn.Close();
Console.WriteLine("Connection Close");
conn.Open();
Console.WriteLine("Connection Open");
DB2Command cmd = null;
int count = 0;
cmd = conn.CreateCommand();
// Create a table 'EMPBOOL1' in the SAMPLE database
Console.WriteLine(" CREATE TABLE EMPBOOL1 WITH ATTRIBUTES:\n" +
" ID SMALLINT NOT NULL,\n" +
" ISMGR BOOLEAN,\n" +
" NAME VARCHAR(9),\n" +
" JOB CHAR(5),\n" +
" PRIMARY KEY(ID)\n");
cmd.CommandText = "CREATE TABLE EMPBOOL1 (" +
" ID SMALLINT NOT NULL," +
" ISMGR BOOLEAN," +
" NAME VARCHAR(9)," +
" JOB CHAR(5)," +
" PRIMARY KEY(ID))";
cmd.ExecuteNonQuery();
Console.WriteLine("\n Table EMPBOOL1 creation Done\n");
// Insert some rows in the table 'EMPBOOL1'
Console.WriteLine(
" INSERT THE FOLLOWING ROWS IN EMPBOOL1:\n" +
" (500, 'TRUE', 'EMP1', 'CLERK'),\n" +
" (510, 'FALSE', 'EMP2', 'MGR'),\n" +
" (520, 'TRUE', 'EMP3', 'SALES'),\n" +
" (530, 'FALSE', 'EMP4', 'MKT')\n");
cmd.CommandText = "INSERT INTO EMPBOOL1(id, ismgr, name, job)" +
" VALUES (500, 'TRUE', 'EMP1', 'CLERK')," +
" (510, 'FALSE', 'EMP2', 'MGR')," +
" (520, 'TRUE', 'EMP3', 'SALES')," +
" (530, 'FALSE', 'EMP4', 'MKT')";
Console.WriteLine();
cmd.ExecuteNonQuery();
Console.WriteLine(" Table EMPBOOL1 insertaion Done\n");
// Select some rows in the table 'EMPBOOL1'
Console.WriteLine(" SELECT id, ismgr, name, job \n" +
" FROM EMPBOOL1 WHERE ismgr = 1\n");
cmd.CommandText = "SELECT id, ismgr, name, job " +
" FROM EMPBOOL1 WHERE ismgr = 1";
DB2DataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
count++;
Console.WriteLine(" -------------");
Console.WriteLine(" Record = {0}", count.ToString());
Console.WriteLine(" -------------");
Console.WriteLine(" ID = {0}", reader.GetInt16(0).ToString());
Console.WriteLine(" ISMGR = {0}", reader.GetInt16(1).ToString());
Console.WriteLine(" NAME = {0}", reader.GetString(2));
Console.WriteLine(" JOB = {0}", reader.GetString(3));
}
reader.Close();
// Update some rows in the table 'EMPBOOL1'
Console.WriteLine("\n UPDTAE EMPBOOL1 SET ismgr = 1 \n" +
" WHERE ID >=520\n");
cmd.CommandText = "update empbool1 set ismgr =1 " +
" where ID >= 520";
Console.WriteLine();
cmd.ExecuteNonQuery();
Console.WriteLine(" Table EMPBOOL1 Updation Done\n");
// Select some rows from the table 'EMPBOOL1'
Console.WriteLine(" SELECT id, ismgr, name, job \n" +
" FROM EMPBOOL1 WHERE ismgr = 1\n");
cmd.CommandText = "SELECT id, ismgr, name, job " +
" FROM EMPBOOL1 WHERE ismgr = 1";
reader = cmd.ExecuteReader();
count = 0;
while (reader.Read())
{
count++;
Console.WriteLine(" -------------");
Console.WriteLine(" Record = {0}", count.ToString());
Console.WriteLine(" -------------");
Console.WriteLine(" ID = {0}", reader.GetInt16(0).ToString());
Console.WriteLine(" ISMGR = {0}", reader.GetInt16(1).ToString());
Console.WriteLine(" NAME = {0}", reader.GetString(2));
Console.WriteLine(" JOB = {0}", reader.GetString(3));
}
reader.Close();
// Delete some rows from the table 'EMPBOOL1'
Console.WriteLine("\n DELETE FROM EMPBOOL1 WHERE ID >=520\n");
cmd.CommandText = "DELETE FROM EMPBOOL1 WHERE ID >=520";
Console.WriteLine();
cmd.ExecuteNonQuery();
Console.WriteLine(" Table EMPBOOL1 Deletion Done for few records\n");
// Select some rows from the table 'EMPBOOL1'
Console.WriteLine(" SELECT id, ismgr, name, job \n" +
" FROM EMPBOOL1 \n");
cmd.CommandText = "SELECT id, ismgr, name, job " +
" FROM EMPBOOL1";
reader = cmd.ExecuteReader();
count = 0;
while (reader.Read())
{
count++;
Console.WriteLine(" -------------");
Console.WriteLine(" Record = {0}", count.ToString());
Console.WriteLine(" -------------");
Console.WriteLine(" ID = {0}", reader.GetInt16(0).ToString());
Console.WriteLine(" ISMGR = {0}", reader.GetInt16(1).ToString());
Console.WriteLine(" NAME = {0}", reader.GetString(2));
Console.WriteLine(" JOB = {0}", reader.GetString(3));
}
reader.Close();
// Delete the table 'EMPBOOL1'
cmd.CommandText = "DROP TABLE EMPBOOL1\n";
cmd.ExecuteNonQuery();
Console.WriteLine(" Table EMPBOOL1 Deletetion Done\n");
// Disconnect from the database
Console.WriteLine("\n Disconnect from the database");
conn.Close();
Console.WriteLine(" Switch off the trace \n");