1. Trang chủ
  2. » Thể loại khác

databasemetadata interface trong jdbc

2 109 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

http://vietjack.com/java_jdbc/index.jsp                                                                                                              Copyright  ©  vietjack.com     DatabaseMetaData Interface JDBC Nếu bạn muốn có thơng tin toàn diện sở liệu, bạn sử dụng phương thức DatabaseMetaData Interface Các thông tin bao gồm tên Database product, phiên Database product, tên driver, tổng số bảng, tổng số view, … Một số phương thức sử dụng phổ biến đối tượng DatabaseMetaData public String getDriverName()throws SQLException Phương thức trả tên JDBC driver public String getDriverVersion()throws SQLException Phương thức trả số hiệu phiên JDBC driver public String getUserName()throws SQLException Phương thức trả username sở liệu public String getDatabaseProductName()throws SQLException Phương thức trả tên Database product public String getDatabaseProductVersion()throws SQLException Phương thức trả phiên Database product public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)throws SQLException Phương thức trả mô tả kiểu bảng Kiểu bảng TABLE, VIEW, ALIAS, SYSTEM TABLE, SYNONYM … Lấy đối tượng DatabaseMetaData JDBC Để lấy đối tượng DatabaseMetaData, bạn sử dụng phương thức getMetaData() Connection Interface với cú pháp: public DatabaseMetaData getMetaData()throws SQLException http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí     http://vietjack.com/java_jdbc/index.jsp                                                                                                              Copyright  ©  vietjack.com     Ví dụ Dưới ví dụ đơn giản để lấy số thông tin sở liệu Driver sử dụng: package com.vietjack.jdbc; import java.sql.*; class ViDuJDBC{ public static void main(String args[]){ try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection( "jdbc:mysql://localhost/sinhvien","root","123456"); DatabaseMetaData dbmd=con.getMetaData(); System.out.println("Ten cua Driver la: "+dbmd.getDriverName()); System.out.println("Driver Version la: "+dbmd.getDriverVersion()); System.out.println("Ten nguoi dung la: "+dbmd.getUserName()); System.out.println("Ten cua Database Product la: "+dbmd.getDatabaseProductName()); System.out.println("Ten cua Database Product Version la: "+dbmd.getDatabaseProductVersion()); con.close(); }catch(Exception e){ System.out.println(e);} } } Bạn chép, dán lưu ví dụ ViDuJDBC.java, sau chạy chương trình Java cho kết quả:   http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí     ... com.vietjack .jdbc; import java.sql.*; class ViDuJDBC{ public static void main(String args[]){ try{ Class.forName("com.mysql .jdbc. Driver"); Connection con=DriverManager.getConnection( "jdbc: mysql://localhost/sinhvien","root","123456");...http://vietjack.com/java _jdbc/ index.jsp                                                                                  ... Connection con=DriverManager.getConnection( "jdbc: mysql://localhost/sinhvien","root","123456"); DatabaseMetaData dbmd=con.getMetaData(); System.out.println("Ten cua Driver la: "+dbmd.getDriverName());

Ngày đăng: 02/12/2017, 22:50

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN