public int addDestine(Destineinfo destine) {
Connection conn = this.getConnection();
PreparedStatement pstmt = null;
int count = 0;
String sql = "insert into destineinfo "
+ "values(destine_seq.nextval,?,"
+ "TO_DATE(?,'yyyy-MM-dd hh24:mi:ss'),?)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, destine.getRoomName());
pstmt.setString(2, destine.getDestineDate());
pstmt.setString(3, destine.getDestineName()); count = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.clossAll(conn, pstmt, null);
}
return count;
}
貌似代码没错。但是运行报错,插入不了数据java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:180)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:542)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1027)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2887)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2959)
at com.dao.impl.DestineinfoDaoImpl.addDestine(DestineinfoDaoImpl.java:57)
at test.Test.main(Test.java:26)
JavaOracle

解决方案 »

  1.   


    package com.dao;import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;public class BaseDao {
    private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
    private static final String URL = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    private static final String USER = "boardroom";
    private static final String PASSWORD = "accp"; static {
    try {
    Class.forName(DRIVER);
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    } public Connection getConnection() {
    Connection conn = null;
    try {
    conn = DriverManager.getConnection(URL, USER, PASSWORD);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return conn;
    } public void clossAll(Connection conn, Statement stmt, ResultSet rs) {
    if (null != rs) {
    try {
    rs.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    if (null != stmt) {
    try {
    stmt.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    if (null != stmt) {
    try {
    stmt.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    }
    //Testpackage test;import java.util.List;import com.dao.DestineinfoDao;
    import com.dao.impl.DestineinfoDaoImpl;
    import com.vo.Destineinfo;public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    DestineinfoDao dedao = new DestineinfoDaoImpl();
    List<Destineinfo> destineList = dedao.equayAll(); for (Destineinfo destineinfo : destineList) {
    System.out.println(destineinfo);
    } Destineinfo ac = new Destineinfo("十一","1020-2-2","wang");
    // System.out.println(dedao.addDestine(v)); dedao.addDestine(ac);
    }}
      

  2.   

    destineinfo表结构定义请讲一下。
      

  3.   

    1、插入到字符串长度大于4000字节。2、插入到表中的记录的某个字段数据的实际长度大于2000个字节(如果是UTF-8,则是1333个字节);或者是插入的记录中有两个或两个以上长度大于2000字节的字符串。
      

  4.   

    很明确了,Long字段插入了非Long型值
      

  5.   

    new Destineinfo("十一","1020-2-2","wang");
      pstmt.setString(2, destine.getDestineDate());
    打印一下destine.getDestineDate()是什么格式,请传入yyyy-MM-dd hh24:mi:ss格式的字符串