Please I have the following problem,
when I run SHOW VARIABLES LIKE '%version%' in mysql command line console it runs very fine, but when I run the same code in the java application I'm working on it produces the following error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'VARIABLES' in 'field list'
ConnectionHelper.setDatabaseName('information_schema');
Statement statement = ConnectionHelper.getStatement();
ResultSet = statement.executeQuery ("SHOW VARIABLES LIKE '%version%'");
String serverVersion = null;
while (resultSet.next()){
serverVersion = resultSet.getString(3);
}
The ConnectionHelper is just a class that creates and sets up a connection to any database passed as parameter to the setDatabaseName() method.
I've even tried not to set any database since the query runs in mysql command line console even without selecting any database, but still produces the same error.
Please I really need help.
解决方案
You can try running this if you just want the DB version:
select VERSION();
I tested this locally
sql = "Select version() as version";
rs = stmt.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getString("version"));
}
Result: 5.6.13
You could also select any MYSQL variable like this:
select @@version as version
The results of your original query on my machine is:
'innodb_version','5.6.13'
'protocol_version','10'
'slave_type_conversions',''
'version','5.6.13'
'version_comment','Source distribution'
'version_compile_machine','x86_64'
'version_compile_os','osx10.8'
So you could select each global variable one by one like this:
select @@version as version,
@@innodb_version as innodb_version,
@@verision_compile_os as version_compile_os
@@protocol_version as protocol_version
@@version_compile_machine as version_compile_machine
.....