who can tell me why?
程序执行后老是抛出“列名错误”,调试了很长时间还这样!真是郁闷死了!请各位大侠帮小弟解决一下!谢了!
import java.sql.*;
import javax.sql.rowset.*;
public class TestRowSet {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
CachedRowSet rowset = new com.sun.rowset.CachedRowSetImpl();
rowset.setUrl("jdbc:mysql://localhost:3306/storedb");
rowset.setUsername("root");
rowset.setPassword("123");
rowset.setCommand("select name,age,address from customers;");
rowset.execute(); //execute()方法负责建立数据库连接,执行查询语句,填充行集,然后关闭数据库连接
rowset.setTableName("customers");//行集的查询结果来自于ResultSet,需显式设置待查询表的表名
rowset.moveToInsertRow();
rowset.updateString("name","xiaohuang");
rowset.updateInt(2,34);
rowset.updateString(3,"jiangsu");
rowset.insertRow();
rowset.moveToCurrentRow();
rowset.acceptChanges();
}
}
customers:
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| name | varchar(16) | NO | | NULL | |
| age | int(11) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
java.sql.SQLException: 列名无效
at com.sun.rowset.CachedRowSetImpl.getColIdxByName(CachedRowSetImpl.java:1601)
at com.sun.rowset.CachedRowSetImpl.getObject(CachedRowSetImpl.java:2985)
at com.sun.rowset.internal.CachedRowSetWriter.insertNewRow(CachedRowSetWriter.java:766)
at com.sun.rowset.internal.CachedRowSetWriter.writeData(CachedRowSetWriter.java:313)
at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:831)
at TestRowSet.main(TestRowSet.java:35)
Exception in thread "main" javax.sql.rowset.spi.SyncProviderException: 列名无效
at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:858)
at TestRowSet.main(TestRowSet.java:35)
import java.sql.*;
import javax.sql.rowset.*;
public class TestRowSet {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
CachedRowSet rowset = new com.sun.rowset.CachedRowSetImpl();
rowset.setUrl("jdbc:mysql://localhost:3306/storedb");
rowset.setUsername("root");
rowset.setPassword("123");
rowset.setCommand("select name,age,address from customers;");
rowset.execute(); //execute()方法负责建立数据库连接,执行查询语句,填充行集,然后关闭数据库连接
rowset.setTableName("customers");//行集的查询结果来自于ResultSet,需显式设置待查询表的表名
rowset.moveToInsertRow();
rowset.updateString("name","xiaohuang");
rowset.updateInt(2,34);
rowset.updateString(3,"jiangsu");
rowset.insertRow();
rowset.moveToCurrentRow();
rowset.acceptChanges();
}
}
customers:
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| name | varchar(16) | NO | | NULL | |
| age | int(11) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
java.sql.SQLException: 列名无效
at com.sun.rowset.CachedRowSetImpl.getColIdxByName(CachedRowSetImpl.java:1601)
at com.sun.rowset.CachedRowSetImpl.getObject(CachedRowSetImpl.java:2985)
at com.sun.rowset.internal.CachedRowSetWriter.insertNewRow(CachedRowSetWriter.java:766)
at com.sun.rowset.internal.CachedRowSetWriter.writeData(CachedRowSetWriter.java:313)
at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:831)
at TestRowSet.main(TestRowSet.java:35)
Exception in thread "main" javax.sql.rowset.spi.SyncProviderException: 列名无效
at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:858)
at TestRowSet.main(TestRowSet.java:35)
...全文
相关推荐
湖北省南漳县肖堰镇肖堰初级中学九年级英语全册《Unit 11 Could you please tell me where th
3) Can you tell me where there is a good place to eat? / Which is the way to the post office?4.
长沙专版2020中考英语复习方案第二篇语法专题突破专题13复合句试题
宾语从句通常由连词(如if, whether, that)或者疑问词(who, what, where, when, why, how)引导。
浙江省2019届中考英语总复习第二篇语法突破篇语法专题十三宾语从句和定语从句试题新版外研版
例如:— Could you tell me whether the train to Beijing will leave? — Certainly.
宾语从句 (2).ppt
Can you tell me where he is?4. Could you tell me how I can get to the station?
医护人员常用英语口语500句5.docx
Where are you from? Can you tell me something more about your hometown?" 这类问题旨在让对方分享他们的文化和生活经历。3.


Web 开发
