谁帮我看下我的这个 oracle JDBC 小程序 错哪呢??

来源:百度知道 编辑:UC知道 时间:2024/05/31 05:17:28
import java.sql.*;

public class TestPrepareStatement {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement pstate = null;
String dname = null;
String loc = null;
int deptno;

try {
//deptno = Integer.parseInt(args[0]);
//dname = args[1];
//loc = args[2];
deptno = 100;
dname = "beia";
loc = "shanghai";

Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
pstate = conn.prepareStatement("insert into dept2 values(?, ?, ?)");
pstate.setInt(1, deptno);
pstate.setString(2, dname);
pstate.setString(3, loc);
pstate.executeUpdate();

} catch (ClassNotFoundException e) {
e.printStackTrace();
} ca

老是出现ORA-01438: value larger than specified precision allows for this column.意思是插入的值对于表中某列来讲太大.该错误提到了precision(精度),所以可以判断该错误是一个有关数字列的问题.经过查看表结构发现, 有几个NUMBER列都全部定义为number(8)或number(8,2)的形式.
NUMBER列的最大精度为38位,如果按number定义,也就是说后面不用定义精度和小数点,就不会出现这个问题,除非是一个很大的浮点数.看oracle的说明:

The NUMBER datatype stores fixed and floating-point numbers. Numbers of virtually
any magnitude can be stored and are guaranteed portable among different systems
operating Oracle, up to 38 digits of precision.
The following numbers can be stored in a NUMBER column:
■ Positive numbers in the range 1 x 10-130 to 9.99...9 x 10125 with up to 38 significant digits
■ Negative numbers from -1 x 10-130 to 9.99...99 x 10125 with up to 38 significant digits
■ Zero
■ Positive and negative infinity (generated only by importing from an Oracle Version 5 database)
For numeric columns, you can specify the column as: