2017-10-08 374 views
-1

我無法使用VS2013從mySQL表中讀取DATETIME值。
我使用的MySQL連接器-1.1.9-Win32的(mysqlcppconn.lib)在C++中獲取mySQL DATETIME值

this is the row containing the datas
這裏是我的代碼:

sql::mysql::MySQL_Driver* m_driver; 
sql::Connection* m_conn; 
sql::Statement* m_stmt; 
sql::ResultSet* m_res; 

m_driver = sql::mysql::get_driver_instance(); 
m_conn = m_driver->connect(ch_hostName, ch_userName, ch_pwd); 

m_stmt = m_conn->createStatement(); 
m_res = m_stmt->executeQuery("select tip, id1, datum from recordLocker where id1 = 'A0001' and tip = 1"); 

try 
{ 
    m_res->getString("datum"); 
} 
catch (sql::SQLException& e) 
{ 
    TRACE1("\nSQL Error %d\n", e.getErrorCode()); 
} 

我歌廳 「SQL錯誤0」
我也試過:

m_res->getInt64("datum"); 
m_res->getUInt64("datum"); 

具有相同的錯誤代碼(m_res不爲空)。

感謝您的幫助!

+0

'DATETIME'既不是字符串,也不是一個整數值。 – user0042

+0

sql :: ResultSet沒有getDateTime()函數,這是我的問題 – janos

回答

0

我將連接器改爲mysql-5.7.19-win32。
此連接器返回字符串格式的所有列,可以將其轉換爲整數,雙精度,...或CTime。

這裏是我的代碼:

MYSQL* m_sql; 
MYSQL* m_conn; 

mysql_init(m_sql) 
m_conn = mysql_real_connect(m_sql, ch_Host, ch_User, ch_Pwd, ch_Db, 0, 0, 0); 

mysql_query(m_conn, "select * from recordLocker"); 

MYSQL_RES* m_res = mysql_use_result(m_conn); 

MYSQL_ROW m_row; 

while(m_row = mysql_fetch_row(m_res)) 
{ 
    CString szDate = CString(mysqlRow[6]); 
    //szDate is in the following format "YYYY-mm-dd hh:mm:ss.000000" 
}