當前位置:首頁 » 編程語言 » java資料庫設計

java資料庫設計

發布時間: 2025-02-23 19:14:23

『壹』 用java設計一個資料庫管理系統

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
//import java.awt.event.*;
public class DisplayDemo extends JFrame
//implements ActionListener
{
// private String dbURL="jdbc:microsoft:sqlserver://202.115.26.181:1433"; // 資料庫標識名
private String user="devon"; // 資料庫用戶
private String password="book"; // 資料庫用戶密碼
private JTable table;
private JButton ok,canel;
public DisplayDemo(){
super("顯示資料庫查詢結果"); //調用父類構造函數
String[] columnNames={"用戶名","年齡","性別","Email"}; //列名
Object[][] rowData=new Object[5][4]; //表格數據
ok=new JButton("確定");
canel=new JButton("取消");
// ok.addActionListener(this);
// canel.addActionListener(this);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:example","sa","");
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //載入驅動器
// Connection con=DriverManager.getConnection(dbURL,user,password); //獲取連接
String sqlStr="select * from users"; //查詢語句
PreparedStatement ps=con.prepareStatement(sqlStr); //獲取PreparedStatement對象
ResultSet rs=ps.executeQuery(); //執行查詢
String name,sex,email; //查詢結果
int age;
int count=0;
while (rs.next()){ //遍歷查詢結果
rowData[count][0]=rs.getString("name"); //初始化數組內容
rowData[count][1]=Integer.toString(rs.getInt("age"));
rowData[count][2]=rs.getString("sex");
rowData[count][3]=rs.getString("email");
count++;
}

con.close(); //關閉連接
}
catch(Exception ex){
ex.printStackTrace(); //輸出出錯信息
}

Container container=getContentPane(); //獲取窗口容器
//container.setLayout(null);
container.add(ok);container.add(canel); ok.setBounds(10,120,70,20);
canel.setBounds(100,120,70,20);
table=new JTable(rowData,columnNames); //實例化表格
table.getColumn("年齡").setMaxWidth(25); //設置行寬
container.add(new JScrollPane(table),BorderLayout.CENTER); //增加組件

setSize(300,200); //設置窗口尺寸
setVisible(true); //設置窗口可視
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //關閉窗口時退出程序
}

public static void main(String[] args){
new DisplayDemo();
}
}

-----------------
這是其中一個例子 你照著上面做就可以了

『貳』 自學Java如何入門

自學Java看這一篇就夠啦!Java學習路線圖分享給你,跟著學習吧!

一、Java基礎

熱點內容
矩陣內的演算法 發布:2025-09-18 20:55:07 瀏覽:569
android網路優化 發布:2025-09-18 20:53:19 瀏覽:216
看交換機配置哪些是默認的 發布:2025-09-18 20:46:59 瀏覽:617
在釘釘上如何獲取自己的密碼 發布:2025-09-18 20:46:12 瀏覽:853
pythonifthenelse 發布:2025-09-18 20:33:19 瀏覽:911
熱血傳奇腳本怎麼做 發布:2025-09-18 20:29:06 瀏覽:609
軒逸手動經典有哪些配置 發布:2025-09-18 20:20:40 瀏覽:625
安卓手機下載軟體在哪裡設置密碼 發布:2025-09-18 20:10:08 瀏覽:608
net業務緩存框架 發布:2025-09-18 19:57:14 瀏覽:16
pythonrst 發布:2025-09-18 19:28:50 瀏覽:415