Page 1 of 1

Getting Error :Could not create a validated object,

Posted: 16 Jul 2014, 12:25
by nikhil
Hello Guys,
I am getting following error on SFS connection with mysql while i am doing any operations related to database.


SQL Failed: java.sql.SQLException: Cannot get a connection, pool error: Could not create a validated object, cause: ValidateObject failed



Following is the code i have used

Code: Select all

	IDBManager dbManager = getParentExtension().getParentZone()
				.getDBManager();
               //any of the following line doesn't make any differance...
		String sql = "SELECT * FROM room;";   or	String sql = "SELECT * FROM room"; 
 
		try {
			// Obtain a resultset
                        trace("check point 1");
			ISFSArray res = dbManager.executeQuery(sql, new Object[] {});
                       trace("check point 2");
			// Populate the response parameters
			ISFSObject response = new SFSObject();
			response.putSFSArray("room", res);
			trace("check point 1 list data");
			// Send back to requester
			send("room_create_handler", response, sender, false);
		} catch (SQLException e) {
			trace(ExtensionLogLevel.WARN,
					"SQL Failed:list_persisted_room " + e.toString());
		}
Error is on line ISFSArray res = dbManager.executeQuery(sql, new Object[] {});


Thanks,
Nikhil.

Re: Getting Error :Could not create a validated object,

Posted: 16 Jul 2014, 13:15
by Lapo
The error indicates that the DBManager is unable to find a valid connection. There can be many causes for this.
One of them is that the "Test SQL" parameter in the DBManager configuration was not specified.

Make sure you configure a valid SQL statement that can be used by the system to validate a connection before using it.

If this doesn't solve the problem post here your DBManager configuration details.

Thanks

Re: Getting Error :Could not create a validated object,

Posted: 16 Jul 2014, 14:11
by nikhil
Thanks For reply
I have research all the way through google and this forum and experimented all the things what i got.

Please find the detail
Test SQL "SELECT 1" even i tried many others.

I have verified all the details regarding SQL Statement things were working fine while i was using local system but not working as i have started testing on live server.
DB manager configuration detail

Database Driver Class org.gjt.mm.mysql.Driver
Connection string jdbc:mysql://localhost:3306/sfs2x
username root(changed)
Password root(changed)
Test SQL SELECT 1
Maximum # of Active Connections 99
Maximum # of idle connections 10
Exhausted pool action GROW
Block time 3000

Please do needful

Re: Getting Error :Could not create a validated object,

Posted: 16 Jul 2014, 14:55
by Lapo
What database are you using?
Also are you using the database connection directly? E.g. by acquiring a connection via getConnection() ?

Also are there any errors related to database activity in the log files? Besides the one you have reported?

Re: Getting Error :Could not create a validated object

Posted: 17 Jul 2014, 06:00
by nikhil
I have tried two different ways for database connections
1) use default zone dbmanager.
2)creating new DBManager as below and getting connection from that.

Code: Select all

SFSDBManager dbm = null;
			// Prepare DBManager configuration
			DBConfig cfg = new DBConfig();

			cfg.active = true;
			cfg.driverName = "org.gjt.mm.mysql.Driver";
			cfg.connectionString = "jdbc:mysql://127.0.0.1/intechug_sfs2x";
			cfg.userName = "db_user_name";
			cfg.password = "db_user_pass";
			cfg.testSql = "SELECT * FROM `room` LIMIT 1";
			// Create DBManager
			dbm = new SFSDBManager(cfg);

i am not getting any other errors related to database activity in the log file.

Re: Getting Error :Could not create a validated object,

Posted: 17 Jul 2014, 10:06
by Lapo
Use the default DBManager, no problem with that. It won't make any difference.

My question is --> are you using in your current code the getConnection() method? If so make sure that you correctly close the connection object in a try/catch/finally block as explained here:
http://docs2x.smartfoxserver.com/Develo ... se-recipes

See "Handling Exceptions" section.

Also. Does the error show up on the very first query you run or does it happen later?
Does it happen on every query? Or occasionally?

Thanks

Re: Getting Error :Could not create a validated object,

Posted: 11 Jan 2024, 22:23
by SmartfoxEnjoyer
I had this same error. For other people getting this error in the future, im posting the solution that worked for me.

After reading the thread I checked my initial test query and it was showing the same error on startup of the server.

The fix is simple make sure you have atleast 1 row of data in the table. Otherwise the test sql will fail and all future db queries will also fail.

That fixed it for me.