2012-07-31 82 views

回答

1

Check This。然後出現任何錯誤,然後把你的代碼以及錯誤行,以便這個社區將幫助你。這不是您從頭開始要求完整代碼的地方。

1

爲了從JTable中檢索數據,你可以用最具體的方法:

Object value = jtable.getValueAt(rowIndex, columnIndex); 

以下應該打開的數據庫連接的codeflow,用mysql例如:

// driver registration 
Class.forName("com.mysql.jdbc.Driver"); 

// create a connection 
Connection connection = DriverManager.getConnection("jdbc:mysql://server_name/database_name","user", "password"); 

// create a statement 
Statement s = connection.createStatement(); 

// execute a query, this method will return the number of affected rows 
int count = s.executeUpdate ("insert into some_table(value) values('" + value + "')); 
+0

爲了便於閱讀,您應該將'conexion'稱爲'連接'並且它是一個連接。 – 2012-07-31 05:23:37

+0

這不是你的母語時發生的:p – manix 2012-07-31 05:25:45

3

這可用於從jTable獲取值並插入到數據庫中,然後創建與數據庫的正確連接。

dbStatement=con.createStatement(); 
for(int i=0;i<=jTable1.getRowCount;i++){ 

       String item=jTable1.getValueAt(i, 1).toString(); 
       String quant=jTable1.getValueAt(i,2).toString(); 
       String unit=jTable1.getValueAt(i, 3).toString(); 
       String tot=jTable1.getValueAt(i, 4).toString(); 

       dbStatement.executeUpdate("INSERT INTO tableName VALUES('"+item+"','"+quant+"','"+unit+"','"+tot+"')"); 

      } 
相關問題