Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java views database information and corresponding table information

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Public class DataBaseMessage {

Public static void main (String [] args) {

GetMessage ()

}

Public static void getMessage () {

Connection connection = null

ResultSet rs = null

Try {

Connection = get connection

DatabaseMetaData dbMetaData = connection.getMetaData ()

System.out.println ("Database related Information:")

System.out.println ("known users:" + dbMetaData.getUserName ())

System.out.println ("comma-separated list of system functions:" + dbMetaData.getSystemFunctions ())

System.out.println ("comma-separated list of time and date functions:" + dbMetaData.getTimeDateFunctions ())

System.out.println ("comma-separated list of string functions:" + dbMetaData.getStringFunctions ())

System.out.println ("supplier's preferred term for 'schema':" + dbMetaData.getSchemaTerm ())

System.out.println ("URL:" + dbMetaData.getURL ())

System.out.println ("allow read-only:" + dbMetaData.isReadOnly ())

System.out.println ("Product name:" + dbMetaData.getDatabaseProductName ())

System.out.println ("version:" + dbMetaData.getDatabaseProductVersion ())

System.out.println ("name of the driver:" + dbMetaData.getDriverName ())

System.out.println ("driver version:" + dbMetaData.getDriverVersion ())

/ / query all the information of the t_file table

Rs = dbMetaData.getColumns (null, null, "Table name", null)

/ / get the information of each record in the t_file table

While (rs.next ()) {

System.out.println (); System.out.println ()

String column_name = rs.getString ("COLUMN_NAME")

String type_name = rs.getString ("TYPE_NAME")

Int column_size = rs.getInt ("COLUMN_SIZE")

Boolean is_nullable = rs.getBoolean ("IS_NULLABLE")

String column_def = rs.getString ("COLUMN_DEF")

System.out.println ("column_name:" + column_name+ "* type_name:" + type_name+ "* column_size:" + column_size+ "* is_nullable:" + is_nullable + "* column_def:" + column_def)

}

} catch (Exception e) {

E.printStackTrace ()

} finally {

Try {

/ / connection.close ()

/ / rs.close ()

} catch (Exception e2) {

E2.printStackTrace ()

}

}

}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report