java中获得jdbc结果集元数据
转自:http://blog.csdn.net/kobe73er/article/details/8250825
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import com.mysql.jdbc.DatabaseMetaData; public class myTestDatabaseMetaData { /** * @param args * @throws ClassNotFoundException * @throws SQLException */ public static void main(String[] args) throws ClassNotFoundException, SQLException { // TODO Auto-generated method stub String mysql_driver = "com.mysql.jdbc.Driver"; String mysql_address = "jdbc:mysql://localhost/test"; String mysql_username = "root"; String mysql_passwd = "root"; Class.forName(mysql_driver); Connection connection = DriverManager.getConnection(mysql_address, mysql_username, mysql_passwd); java.sql.DatabaseMetaData dbMetaData = connection.getMetaData(); // 获得driver版本 System.out.println(dbMetaData.getDriverName()); // 获得产品名字 System.out.println(dbMetaData.getDatabaseProductName()); // 获得产品版本 System.out.println(dbMetaData.getDatabaseProductVersion()); // 获得最大连接数 System.out.println(dbMetaData.getMaxConnections()); // 获得一个表能容纳的最大列数 System.out.println(dbMetaData.getMaxColumnsInTable()); connection.close(); } }