select name,id from 表名
如果更改表结构:
alter table 表名 modify column id int auto_increment after name
比如:
#建立测试表 t1
mysql>create table t1(id int auto_increment,name varchar(20),primary key(id))engine=innodb,default charset=utf8
Query OK, 0 rows affected (0.11 sec)
#插入3条数据
mysql>insert into t1(name) values ("aa"),("bb"),("cc")
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>select * from t1
+----+------+
| id | name |
+----+------+
| 1 | aa |
| 2 | bb |
| 3 | cc |
+----+------+
3 rows in set (0.00 sec)
#结果集中排列name到id前
mysql>select name,id from t1
+------+----+
| name | id |
+------+----+
| aa | 1 |
| bb | 2 |
| cc | 3 |
+------+----+
3 rows in set (0.00 sec)
#改变表结构,使name在id前
mysql>alter table t1 modify column id int auto_increment after name
Query OK, 3 rows affected (0.19 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>select * from t1
+------+----+
| name | id |
+------+----+
| aa | 1 |
| bb | 2 |
| cc | 3 |
+------+----+
3 rows in set (0.00 sec)
mysql>desc t1
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
+-------+-------------+------+-----+---------+----------------+
SAXReaderreader
=
new
SAXReader()
Document
doc=reader.read(new
File("src/Cinema.xml"))
Element
eleRoot=doc.getRootElement()
for(Iterator
its=eleRoot.elementIterator()its.hasNext()){
Element
eleCount=(Element)its.next()
Iterator
it=eleCount.elementIterator()
while(it.hasNext()){
Element
eleName=(Element)it.next()
}
用这些代码可以实现从XML中读取数据
然后建立连接用一个实体类用来临时存放SQL数据把
用List<News>存放
Class.forName("oracle.jdbc.OracleDriver")
String
url="jdbc:oracle:thin:@192.168.0.200:1521:tarena"
Connection
con=DriverManager.getConnection(url,"hsd1103","hsd1103")
String
str="insert
into
news
value(?,?,?,?,?)"//问号是对应下面你所要传递的值和
你SQL中的字段值对应
News
news=new
News()
PreparedStatement
stmt=PreparedStatement
pstm
=
con.prepareStatement()
//把xml中的数据放置到sql中
stmt.setInt(1,news.getID())
stmt.setString(2,news.getName)
stmt.setString(3,news.getAcc())
.
.
.
按照这样的方式些就可以了我用的是oracle
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)