?? databaseinfo.java
字號:
import javax.swing.*;
import java.sql.*;
public class DatabaseInfo extends JFrame {
JTextArea taInfo=new JTextArea();
public DatabaseInfo() {
super("數據庫信息");
setSize(300,260);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
this.getContentPane().add(taInfo);
}
public void getDatabaseInfo(){
Connection con=null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
taInfo.setText(ex.getMessage());
System.exit(-1);
}
try{
String URL = "jdbc:odbc:學生信息管理";
con = DriverManager.getConnection(URL);
DatabaseMetaData dbmt=con.getMetaData();
taInfo.setText("JDBC URL:"+dbmt.getURL()+"\n");
taInfo.append("JDBC 驅動程序:"+dbmt.getDriverName()+"\n");
taInfo.append("用戶賬號:"+dbmt.getUserName()+"\n");
taInfo.append("數據庫名:"+dbmt.getDatabaseProductName()+"\n");
con.close();
}
catch(SQLException ex){
taInfo.setText(ex.getMessage());
}
}
public static void main(String[] args) {
DatabaseInfo frame = new DatabaseInfo();
frame.getDatabaseInfo();
frame.show();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -