Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

Prepared Statement continuously returning null set (1 reply)

$
0
0
I'll admit I'm new at this (clearly, this being my second post in several hours). The basic setup is such: I'm currently using two C++ applications I wrote to connect to eachother. One machine serves as a log-in server, and is running MySQL with a users table as a background process. The other sends login data (handle and password) via WinSock2. The server received the info and queries the database. However, every time I query it throws an exception, and I have no idea how to fix it.

Running the same query using the MySQL command prompt yields a 1x1 table with the user's password.

Here is my code:

cout<<"Connecting to SQL database"<<endl;
m_SQLDriver = get_driver_instance();
m_SQLCon = m_SQLDriver->connect("tcp://127.0.0.1:3306/nebulous", "root", "**pass**");
m_SQLCon->setAutoCommit(false);

...

try
{
cout<<"Querying SQL Database"<<endl;

m_SQLPrepStatement = m_SQLCon->prepareStatement("SELECT password FROM users WHERE handle = (?)");
m_SQLPrepStatement->setString(1, handle);
m_SQLResultSet = m_SQLPrepStatement->executeQuery();

std::string Pass = password;

/*if(m_SQLResultSet->wasNull())
{
cout<<"Query returned null result."<<endl;
respond = LOGIN_RESULT_USERNAMEBAD;
}*/
if(Pass == m_SQLResultSet->getString("password"))
{
cout<<"Password match. Login successful."<<endl;
respond = LOGIN_RESULT_ACCEPTED;
}
else
{
cout<<"Password mismatch. Login FAILED."<<endl;
respond = LOGIN_RESULT_PASSBAD;
}
}
catch(sql::SQLException &e)
{
cout<<"ServerHandler::ReadPackets() Caught MySQL error on log-in attempt"<<endl;
cout<<"ERROR: "<<e.what()<<endl;
cout<<"/t(MySQL error code: "<<e.getErrorCode()<<endl;

respond = LOGIN_RESULT_MYSQLERROR;
}

If anyone has run into this before, or knows what I'm doing wrong (I'm sure there's plenty of it), I'd appreciate the help.

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>