2012-07-31 92 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+"')"); 

      } 
相关问题