java把JTable中的数据插入到数据库问题
请教:如何将JTable中数据插入到数据库中如题我尝试了将JTabele中数据取出来但是不能将数据插入到数据库中请问大家有什么改正办法没有谢谢了一下是部分代码请看看if(...
请教:如何将JTable中数据 插入到数据库中
如题
我尝试了将JTabele中数据取出来 但是不能将数据插入到数据库中
请问大家有什么改正办法没有 谢谢了
一下是部分代码请看看
if (e.getSource() == jButton2) {
int rows = drawfrm.mainTable.getRowCount();
String c1=null,c2=null,c3=null,c4=null,c5=null,c6=null,c7=null,c8=null,c9=null;
for (int i = 1; i < rows; i++) {
c1 = String.valueOf(drawfrm.mainTable.getValueAt(i, 1));
c2 = String.valueOf(drawfrm.mainTable.getValueAt(i, 2));
c3 = String.valueOf(drawfrm.mainTable.getValueAt(i, 3));
c4 = String.valueOf(drawfrm.mainTable.getValueAt(i, 4));
c5 = String.valueOf(drawfrm.mainTable.getValueAt(i, 5));
c6 = String.valueOf(drawfrm.mainTable.getValueAt(i, 6));
c7 = String.valueOf(drawfrm.mainTable.getValueAt(i, 7));
c8 = String.valueOf(drawfrm.mainTable.getValueAt(i, 8));
c9 = String.valueOf(drawfrm.mainTable.getValueAt(i, 9));
}
String url = "jdbc:odbc:driver={MicroSoft Access Driver (*.mdb)};DBQ=D:/error.mdb";//NO-DSN模式
String username = "";
String password = "";
Connection con = null;
String sql = null;
ResultSet rs = null;
Statement stmt = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,username,password);
stmt = con.createStatement();
sql="insert into errordata values("+ c1 + ","+ c2 + "," + c3 + ","
+ c4 + ","
+ c5 + ","
+ c6 + ","
+ c7 + ","
+ c8 + ","
+ c9 + ")";
stmt.executeUpdate(sql);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
数据库显示记录数不为0,
但是插入的数据却都是null,各个记录都是空白
请大家帮帮忙
谢谢了
急!!谢谢各位了!!! 展开
如题
我尝试了将JTabele中数据取出来 但是不能将数据插入到数据库中
请问大家有什么改正办法没有 谢谢了
一下是部分代码请看看
if (e.getSource() == jButton2) {
int rows = drawfrm.mainTable.getRowCount();
String c1=null,c2=null,c3=null,c4=null,c5=null,c6=null,c7=null,c8=null,c9=null;
for (int i = 1; i < rows; i++) {
c1 = String.valueOf(drawfrm.mainTable.getValueAt(i, 1));
c2 = String.valueOf(drawfrm.mainTable.getValueAt(i, 2));
c3 = String.valueOf(drawfrm.mainTable.getValueAt(i, 3));
c4 = String.valueOf(drawfrm.mainTable.getValueAt(i, 4));
c5 = String.valueOf(drawfrm.mainTable.getValueAt(i, 5));
c6 = String.valueOf(drawfrm.mainTable.getValueAt(i, 6));
c7 = String.valueOf(drawfrm.mainTable.getValueAt(i, 7));
c8 = String.valueOf(drawfrm.mainTable.getValueAt(i, 8));
c9 = String.valueOf(drawfrm.mainTable.getValueAt(i, 9));
}
String url = "jdbc:odbc:driver={MicroSoft Access Driver (*.mdb)};DBQ=D:/error.mdb";//NO-DSN模式
String username = "";
String password = "";
Connection con = null;
String sql = null;
ResultSet rs = null;
Statement stmt = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,username,password);
stmt = con.createStatement();
sql="insert into errordata values("+ c1 + ","+ c2 + "," + c3 + ","
+ c4 + ","
+ c5 + ","
+ c6 + ","
+ c7 + ","
+ c8 + ","
+ c9 + ")";
stmt.executeUpdate(sql);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
数据库显示记录数不为0,
但是插入的数据却都是null,各个记录都是空白
请大家帮帮忙
谢谢了
急!!谢谢各位了!!! 展开
4个回答
展开全部
貌似语句写错了吧,插入值需要有单引号的'';
sql="insert into errordata values(‘"+ c1 + "’,‘"+ c2 + "’,‘" + c3 + "’,‘"
+ c4 + "’,‘"
+ c5 + "‘,’"
+ c6 + "‘,’"
+ c7 + "‘,’"
+ c8 + "‘,’"
+ c9 + "’)";
仅供参考,先吃饭去了~~~
sql="insert into errordata values(‘"+ c1 + "’,‘"+ c2 + "’,‘" + c3 + "’,‘"
+ c4 + "’,‘"
+ c5 + "‘,’"
+ c6 + "‘,’"
+ c7 + "‘,’"
+ c8 + "‘,’"
+ c9 + "’)";
仅供参考,先吃饭去了~~~
追问
加了也还是null,无语了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有没出异常?JTabel的行列号都是从0开始的。你这里用1真的没有问题吗?是不是这个原因啊。数组越界!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
注意查收。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |