2014-01-10 90 views
-1

我的结构:C++ Mysql的变量插入

long int uuId; 
short int cameraNo; 

声明:

pstmt = con -> prepareStatement("INSERT INTO Amts(UUID,KameraNo) VALUES("<< first.uuId <<"," << first.cameraNo <<");"); 

我已经写了这个代码,但它不是C++的作品,我怎么可以将这些变量到数据库?

错误:

main.cpp:72:48: error: invalid operands of types ‘const char [79]’ and ‘long long int’ to binary ‘operator<<’

编辑:

prepStmt = con -> prepareStatement("INSERT INTO Amts VALUES (?,?)"); 

     prepStmt -> setInt(1,first.uuId); 
     prepStmt -> setInt(2,first.cameraNo); 

     prepStmt -> executeUpdate(); 

此代码已经成功的工作,但如果我不知道如何使用内部长变量SETINT

+0

你会得到什么错误? – wgcrouch

+0

详情请。什么不行,什么是错误? – AdrianBR

+0

添加了错误代码。 – Duke

回答

0

试试这个:

long int uuId; 
short int cameraNo; 
std::stringstream s; 
s << "INSERT INTO Amts(UUID,KameraNo) VALUES("<< first.uuId <<"," << first.cameraNo <<");"; 
pstmt = con -> prepareStatement(s.str()); 
+0

没有错误,但它不影响数据库,也cout << s.str();什么也不印。 – Duke

+0

请看这里http://codepad.org/5TtlU93r – PermanentGuest

+0

是的,它的工作原理,谢谢。 – Duke