[英]How to design a storage system for this?
我真的很想為此設計數據庫。
這是我自己的CS項目。 這意味着整個代碼就是我的主意。 無論如何,我想知道最有效的方法來存儲圖片中顯示的所有信息。
我曾考慮過使用ArrayList,但我反復詢問自己是否可以使用arraylist。 我可能可以使用數據庫,但還沒有學習。
圖片應該很容易解釋。 所有這些信息僅屬於1個學生。 那么,如何設計最好的數據存儲系統來存儲至少20個學生的信息?
由於我無法發布圖片,請點擊此鏈接: http : //j.stack.imr.com/0Q.png
感謝幫助。
看起來一個案例是一個數據庫表每個學生一行,而另一個數據庫表每個作業一行。 我要么讓數據庫為我存儲的每條學生記錄創建索引(關系數據庫中的當前方式),要么我可以假設其唯一且永久的身份使用學生ID號(我認為這是一個較差的選擇)。 每個學生記錄和每個作業記錄都具有該索引,因此每個作業都與一個學生和一個學生相關聯,但是您可以將許多作業與一個學生相關聯。
有許多可用的免費數據庫。 我曾經使用過並且喜歡Derby; 如果僅從此程序訪問它,則可以將其用作“嵌入式”數據庫,從而省去了運行數據庫服務器以連接程序的麻煩。
祝好運。
我認為最好的方法是通過數據庫。
既然您提到過,您對DB的了解並不多,讓我為您指明正確的方向
首先安裝XAMPP (這將允許您在本地計算機上創建MySQL數據庫)
您必須將JDBC驅動程序安裝到您的IDE中(使用的是netbeans或eclipse)
在您的項目中或多或少創建一個像這樣的類
public class SQLConnect
{
public static Connection ConnectDb()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/w1283057", "root", "");
} catch (SQLException ex) {
Logger.getLogger(SQLConnect.class.getName()).log(Level.SEVERE, null, ex);
}
return conn;
}
catch (ClassNotFoundException e)
{
System.out.println("not connected");
e.printStackTrace();//print extra info if error is thrown
return null;
}
}
}
那么您可以在其他類上創建SaveActionPerformed(無論您在哪里擁有表單表)
它可能看起來像這樣(請不要在這里與SQLConnect類建立連接以及將數據插入數據庫的地方
public class Something extends javax.swing.JFrame
{
Connection conn = null; //A connection (session) with a specific database
ResultSet rs = null; //A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
PreparedStatement pst = null; //An object that represents a precompiled SQL statement.A SQL statement is precompiled and stored in that object
private void SaveActionPerformed(jawa.awt.event.ActionEvent evt)
{
try{
conn = SQLConnect.ConnectDb();
//inserting all values to database
String sql = "INSERT INTO bla"
+ "(foo, foo1, foo2, foo3, foo4, etc"
+ "VALUES (?, ?, ?, ?, ?)";
pst = conn.prepareStatement(sql);
//Than you take all values from the fields and put them into db
// i.e. You have field name Mark. In order to put this into db you need
pst.setString(1, Mark); <- this means that preparestatement will put whatever is in the mark into first column.
pst.executeUpdate(); <- order to execute
}
希望這將使您走上正確的道路
對我來說,最好的方法是使用Postgresql。 您只需要一個學生表(例如),將在其中存儲所有學生數據。 之后,您可以創建一個或多個(取決於您)的班級,該班級將描述表格並執行諸如搜索學生之類的操作。 Postgresql的主要優點是不需要服務器! 這是一個教程
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.