mysql @@version_MYSQL-显示变量类似'%version%'在我的Java应用程序中不起作用

bd96500e110b49cbb3cd949968f18be7.png

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

.....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值