How to detect database type?

我们两清 提交于 2020-01-15 11:33:11

问题


I need to be sure the database I'm connecting to is MySQL and not PostgreSQL or Microsoft SQL Server.How can I find out which type of database is being used .


回答1:


The first hint might be the "connection error" you're likely to get if you try to connect to a PostgreSQL database with a mySQL database driver :)

Basically, you need to:

1) Code your application in a portable manner (don't use MSSQL extensions in a query that might be run on mySql, for example)

2) Choose a portable driver API (like JDBC, ODBC, ADO.Net, etc)

3) Provide some mechanism for your application to query the actual database type at runtime (for example, an .config properties file)

4) Test your completed application against each of the supported database types.

'Hope that helps .. PSM




回答2:


You can check for the running database process on the host your trying to connect.

Example: ps -ef | grep mysql




回答3:


Judging from your comments, you have an SQL CLI-like interface or you can only execute SQL queries and you want to know if it's a mysql server answering your queries.

You could use

SELECT @@version_comment

which will return something like MySQL Community Server if it's a MySQL server



来源:https://stackoverflow.com/questions/9917037/how-to-detect-database-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!