java.sql.SQLException: Invalid scale size. Cannot be less than zero
数据库Oracle 10203
数据库Oracle 10203
package com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.sql.rowset.*;
import com.sun.rowset.CachedRowSetImpl;;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.sql.rowset.*;
import com.sun.rowset.CachedRowSetImpl;;
public class Test {
public static void main(String arg[]) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@***.***.***.***:1521:billdb2";
Connection c = DriverManager.getConnection(url,"test","test");
Statement s = c.createStatement();
ResultSet r = s.executeQuery("select * from b");
CachedRowSet crs = new CachedRowSetImpl();
crs.populate(r);
while(crs.next()){
System.out.println(crs.getInt(1));
System.out.println(crs.getFloat(2));
}
}catch(Exception e) {
System.out.println(e.toString());
}
}
public static void main(String arg[]) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@***.***.***.***:1521:billdb2";
Connection c = DriverManager.getConnection(url,"test","test");
Statement s = c.createStatement();
ResultSet r = s.executeQuery("select * from b");
CachedRowSet crs = new CachedRowSetImpl();
crs.populate(r);
while(crs.next()){
System.out.println(crs.getInt(1));
System.out.println(crs.getFloat(2));
}
}catch(Exception e) {
System.out.println(e.toString());
}
}
}
SQL> desc a
Name Type Nullable Default Comments
---- ------ -------- ------- --------
ID NUMBER Y
ID2 NUMBER Y
Name Type Nullable Default Comments
---- ------ -------- ------- --------
ID NUMBER Y
ID2 NUMBER Y
SQL> desc b
Name Type Nullable Default Comments
---- ----------- -------- ------- --------
ID NUMBER(1) Y
ID2 NUMBER(5,2) Y
Name Type Nullable Default Comments
---- ----------- -------- ------- --------
ID NUMBER(1) Y
ID2 NUMBER(5,2) Y
使用CachedRowSetImpl 接口,如果数据库表字段为number且未指定精度(如a表),就会出现该错误。
如果指定精度程序运行正常(如b表)
使用CachedRowSetImpl 接口,如果数据库表字段为number且未指定精度,就会出现该错误。