weixin_42327899 2009-07-31 18:04
浏览 287
已采纳

ibatis 中向oracle 表插入一条记录

SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMapConfig

PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"

"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<!-- Configure a built-in transaction manager. If you're using an
app server, you probably want to use its transaction manager
and a managed datasource -->







<!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->

<!-- List more here...


-->

User.xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap

PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"

"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<!-- Use type aliases to avoid typing the full classname every time. -->

<!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. -->



<!-- Select with no parameters using the result map for Account class. -->

select * from UserT


insert into UserT (
id,name
values (
#id#,#name#
)

User.java

package com.xlh.ibatis.model;

public class User {

private int id ;
private String name ;
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

}

package com.xlh.ibatis;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.xlh.ibatis.model.User;

public class testIbatis {

/**
 * @param args
 */
private static SqlMapClient sqlMapper ;
static {
    try {
      Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
      sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
      reader.close(); 
    } catch (IOException e) {
      // Fail fast.
      throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
    }
  }
public static void main(String[] args) {
    // TODO Auto-generated method stub

    insert() ;
    select() ;

}

public static void select() {
    try {
        List list = sqlMapper.queryForList("selectAllAccounts");
        Iterator it = list.iterator() ;
        while (it.hasNext()) {
            User user = (User)it.next() ;

            System.out.println(user.getName()) ;
            System.out.println(user.getId()) ;

        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

public static void insert() {
    User user = new User() ;
    user.setId(2) ;
    user.setName("laogao") ;


    //插入一条记录
    try {
        sqlMapper.insert("insertAccount", user) ;
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

执行主函数时出现
com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in com/xlh/ibatis/User.xml.

--- The error occurred while applying a parameter map.

--- Check the insertAccount-InlineParameterMap.

--- Check the statement (update failed).

--- Cause: java.sql.SQLException: ORA-00917: 缺少逗号

at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:91)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:447)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:59)
at com.xlh.ibatis.testIbatis.insert(testIbatis.java:62)
at com.xlh.ibatis.testIbatis.main(testIbatis.java:33)

Caused by: java.sql.SQLException: ORA-00917: 缺少逗号

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:81)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78)
... 5 more

aaa
1

请问哪儿出问题了.
我刚接触ibatis

  • 写回答

1条回答 默认 最新

  • imlyj 2009-08-01 20:00
    关注


    insert into UserT (
    id,name [color=red])[/color]
    values (
    #id#,#name#
    )

    是不是缺个右括号,红色的地方

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?