當前位置:首頁 » 編程語言 » 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-02-24 00:15:12 瀏覽:659
電腦裝伺服器硬體 發布:2025-02-23 23:56:13 瀏覽:730
電腦突然提示伺服器狀態變更 發布:2025-02-23 23:38:46 瀏覽:787
網站攻擊源碼 發布:2025-02-23 23:38:45 瀏覽:999
余額寶的錢怎麼配置 發布:2025-02-23 23:37:24 瀏覽:391
廣州全國性檔案存儲服務熱線 發布:2025-02-23 23:32:23 瀏覽:467
維特拉怎麼選配置 發布:2025-02-23 23:31:44 瀏覽:734
androidfor循環 發布:2025-02-23 23:27:31 瀏覽:100
神奇數字密碼大約有多少字 發布:2025-02-23 23:22:23 瀏覽:624
meshes文件夾 發布:2025-02-23 23:18:54 瀏覽:774