What is IllegalStateException?

2019-01-24 00:31发布

I am trying to use the following Fastload API

connection ... etc is perfect.


I know exactly where it fails

 ...........
 System.out.println(" Streaming " + dataFile);
 pstmtFld.setAsciiStream(1, dataStream, -1); // This line fails
 System.out.println("check the above line"); // This does not go to console
 ...........

Exception is

Exception in thread "main" java.lang.IllegalStateException: Sample failed.

[ODBC Teradata Driver] Invalid precision: cbColDef value out of range


Here is my table that I am trying to upload. It is a .csv format and when I open it via notepad it look like this

1,9,Win
2,9,Winc
3,9,Wi

Why do I get this exception? How can I improve it? As far as I understand the problem is pstmtFld.setAsciiStream(1, dataStream, -1); does not accept the dataset somehow and throw an exception

3条回答
Ridiculous、
2楼-- · 2019-01-24 00:46

Illegal State Exception is an Unchecked exception.

It indicate that method has been invoked at wrong time.

example:

Thread t = new Thread();
t.start();
//
//
t.start();

output:

Runtime Excpetion: IllegalThreadStateException

We cant start the Thread again, it will throw IllegalStateException.

查看更多
贼婆χ
3楼-- · 2019-01-24 00:55
package com.concepttimes.java;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IllegalStateExceptionDemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List al = new ArrayList();
        al.add("Sachin");
        al.add("Rahul");
        al.add("saurav");
        Iterator itr = al.iterator();  
        while (itr.hasNext()) {           
            itr.remove();
        }
    }
}

IllegalStateException signals that method has been invoked at the wrong time. In this below example, we can see that. remove() method is called at the same time element is being used in while loop.

Please refer to below link for more details. http://www.elitmuszone.com/elitmus/illegalstateexception-in-java/

查看更多
虎瘦雄心在
4楼-- · 2019-01-24 01:02

Usually, IllegalStateException is used to indicate that "a method has been invoked at an illegal or inappropriate time." However, this doesn't look like a particularly typical use of it.

The code you've linked to shows that it can be thrown within that code at line 259 - but only after dumping a SQLException to standard output.

We can't tell what's wrong just from that exception - and better code would have used the original SQLException as a "cause" exception (or just let the original exception propagate up the stack) - but you should be able to see more details on standard output. Look at that information, and you should be able to see what caused the exception, and fix it.

查看更多
登录 后发表回答