当前位置:编程学习 > JAVA >>

java中获得jdbc结果集元数据

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());
// 获得最大连接数 www.zzzyk.com
System.out.println(dbMetaData.getMaxConnections());
// 获得一个表能容纳的最大列数
System.out.println(dbMetaData.getMaxColumnsInTable());
connection.close();
}

 

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,