how to obtain query execution time?
i need for mysql query in java...
does anyone know

if you are using mysql 5.1 versions
then u can query general_log table to get the execution time

i dont think we can do it in Mysql 5.0 or lesser versions

if you got any thing show us some light

In php, we make use of microtime to find the execution time.

$starttime = microtime();
$query = mysql_query("select * from table");
$endtime = microtime();

Then calculate the difference between $starttime and $endtime. I am sure you can do the same in java as well !

i have found another solution

it is in mysql it self
1st. u need to sent a query to mysql with "set profiling=1" i do this after mysql connects & selects the db,

next i made a pretty little function that returns th query time
here is the function:

function Query_time ($displ = false) {
	$qt = 0;
	$qn = 0;
	$sql_time = QueryResultsAsArray("SHOW profiles");
	foreach ($sql_time as $o) {
	$qt = number_format($o->Duration + $qt,6,'.',' ');
	$qn++;
	}
	if ($displ == false)
	return $qt;
	else echo "$qn Querys in ".$qt." sec.";
	return ;
}

and u simply use this function to display the time it took the mysql to execute the query
i hope it helpd :)

i have found another solution

it is in mysql it self
1st. u need to sent a query to mysql with "set profiling=1" i do this after mysql connects & selects the db,

next i made a pretty little function that returns th query time
here is the function:

function Query_time ($displ = false) {
	$qt = 0;
	$qn = 0;
	$sql_time = QueryResultsAsArray("SHOW profiles");
	foreach ($sql_time as $o) {
	$qt = number_format($o->Duration + $qt,6,'.',' ');
	$qn++;
	}
	if ($displ == false)
	return $qt;
	else echo "$qn Querys in ".$qt." sec.";
	return ;
}

and u simply use this function to display the time it took the mysql to execute the query
i hope it helpd :)

I want to show profiles data to php....

Can U show me a full code... code i got error at
$sql_time = QueryResultsAsArray("SHOW profiles");

thnks so much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.