In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
(1)DatabaseMetaData:
package javase.jdbc;import java.sql.Connection;import java.sql.DatabaseMetaData;import java.sql.ResultSet;import java.sql.SQLException;public class DatabaseMetaDataDemo { public static void main(String[] args) { Connection connection = JDBCConnection.getConnection(); try { DatabaseMetaData dMetaData = connection.getMetaData(); //instantiate metadata System.out.println("database name: " + dMetaData.getDatabaseProductName()); System.out.println("Database version: " + dMetaData.getDatabaseProductVersion()); ResultSet resultSet = dMetaData.getPrimaryKeys(null, null, "users"); while (resultSet.next()) { System.out.println("Table Category: " + resultSet.getString(1)); System.out.println("table schema: " + resultSet.getString(2)); System.out.println("table name: " + resultSet.getString(3)); System.out.println("Column Name: " + resultSet.getString(4)); System.out.println("PK: " + resultSet.getString(5)); System.out.println("Primary key name: " + resultSet.getString(6)); } } catch (SQLException e) { e.printStackTrace(); } }}
Output:
Database Name: MySQL Database Version: 5.5.19 Table Category: jdbcdemo Table Mode: null Table Name: users Column Name: id Primary Key: 1 Primary Key Name: PRIMARY
(2)ResultSetMetaData:
package javase.jdbc;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSetMetaData;import java.sql.SQLException;public class ResultSetMetaDataDemo { public static void main(String[] args) { String sql = "SELECT id,username,password,classId FROM users"; Connection connection = JDBCConnection.getConnection(); try { PreparedStatement pStatement = connection.prepareStatement(sql); ResultSetMetaData rSetMetaData = pStatement.getMetaData(); System.out.println("Return data has" + rSetMetaData.getColumnCount() + "fields"); if (rSetMetaData.isAutoIncrement(1)) System.out.println(rSetMetaData.getColumnName(1) + "field is self-increasing"); } catch (SQLException e) { e.printStackTrace(); } }}
Output:
The returned data has 4 fields. The id field is self-increasing.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.