请教:如何将JTable中数据 插入到数据库中
如题代码在附件中 我尝试了将JTabele中数据取出来 但是不能将数据插入到数据库中
请问大家有什么改正办法没有 谢谢了
一下是部分代码请看看
if (e.getSource() == jButton2) {
int rows = jTable1.getRowCount();
String c1=null,c2=null,c3=null,c4=null,c5=null,c6=null,c7=null,c8=null,c9=null,c10=null;
for (int i = 1; i < rows; i++) {
c1 = (String) jTable1.getValueAt(i, 1);
c2 = (String) jTable1.getValueAt(i, 2);
c3 = (String) jTable1.getValueAt(i, 3);
c4 = (String) jTable1.getValueAt(i, 4);
c5 = (String) jTable1.getValueAt(i, 5);
c6 = (String) jTable1.getValueAt(i, 6);
c7 = (String) jTable1.getValueAt(i, 7);
c8 = (String) jTable1.getValueAt(i, 8);
c9 = (String) jTable1.getValueAt(i, 9);
c10 = (String) jTable1.getValueAt(i, 10);
}
Connection con = null;
String sql = null;
ResultSet rs = null;
Statement stmt = null;
try {
Class.forName(
"com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jinxiaocun",
"sa",
"");
stmt = con.createStatement();
sql="insert into shangpindan values("
+ c1 + ","
+ c2 + ","
+ c3 + ","
+ c4 + ","
+ c5 + ","
+ c6 + ","
+ c7 + ","
+ c8 + ","
+ c9 + ","
+ c10 + ")";
stmt.executeUpdate(sql);
System.out.print("aaaa");
} catch (Exception ex) {
ex.printStackTrace();
}
}
可以插入
但是插入的数据却都是null
请大家帮帮忙
谢谢了
[[it] 本帖最后由 elan1986 于 2008-10-25 14:27 编辑 [/it]]
JinHuoDan.rar
(2.29 KB)