質問編集履歴
1
ソースコード編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,9 +34,11 @@
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
-
#include<
|
37
|
+
#include <stdlib.h>
|
38
38
|
|
39
|
+
#include <iostream>
|
40
|
+
|
39
|
-
#include
|
41
|
+
#include "driver/mysql_connection.h"
|
40
42
|
|
41
43
|
#include <cppconn/driver.h>
|
42
44
|
|
@@ -46,35 +48,65 @@
|
|
46
48
|
|
47
49
|
#include <cppconn/statement.h>
|
48
50
|
|
49
|
-
#include <cppconn/prepared_statement.h>
|
50
|
-
|
51
51
|
|
52
52
|
|
53
53
|
using namespace std;
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
int main()
|
57
|
+
int main(void)
|
60
58
|
|
61
59
|
{
|
62
60
|
|
61
|
+
try {
|
63
62
|
|
63
|
+
sql::Driver *driver;
|
64
64
|
|
65
|
-
|
65
|
+
sql::Connection *con;
|
66
66
|
|
67
|
-
|
67
|
+
sql::Statement *stmt;
|
68
68
|
|
69
|
-
|
69
|
+
sql::ResultSet *res;
|
70
|
-
|
71
|
-
//ここでエラー発生 ハンドルされていない Win32のエラー
|
72
|
-
|
73
|
-
con = driver->connect("tcp://localhost:3306", "root", "");
|
74
70
|
|
75
71
|
|
76
72
|
|
73
|
+
driver = get_driver_instance();
|
74
|
+
|
75
|
+
//ここでWin32の例外が発生
|
76
|
+
|
77
|
+
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
|
78
|
+
|
79
|
+
|
80
|
+
|
77
|
-
|
81
|
+
delete res;
|
82
|
+
|
83
|
+
delete stmt;
|
84
|
+
|
85
|
+
delete con;
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
} catch (sql::SQLException &e) {
|
90
|
+
|
91
|
+
cout << "# ERR: SQLException in " << __FILE__;
|
92
|
+
|
93
|
+
cout << "(" << __FUNCTION__ << ") on line "<< __LINE__ << endl;
|
94
|
+
|
95
|
+
cout << "# ERR: " << e.what();
|
96
|
+
|
97
|
+
cout << " (MySQL error code: " << e.getErrorCode();
|
98
|
+
|
99
|
+
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
cout << endl;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
return EXIT_SUCCESS;
|
78
110
|
|
79
111
|
}
|
80
112
|
|