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
解决方案 »
- struts总是找不到国际化资源文件
- 问一简单的问题.....
- 急急急~~resin2.1启动时错误can't create socket;换成tomcat则:Unrecogized sockets error:10106:create
- 怎么在后台获得<logic:iterate>输出的list
- 初学者请教问题之八:时间问题
- 服务器配置问题
- filter解决汉字输入的问题 为什么我编好没有专成gb2312
- 时间问题
- ZipOutputStream如何转化为ServletOutputStream,求高手,万分感谢,在线等!
- 求助各位大神:一对一,Hibernate 下正常,但是SSH下只能保存主表信息。
- Java Web 聊天的实现机制是怎么样的
- 来问下大批量数据的问题(5亿左右的数据量)
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);
}}
pstmt.setString(2, destine.getDestineDate());
打印一下destine.getDestineDate()是什么格式,请传入yyyy-MM-dd hh24:mi:ss格式的字符串