Any help?
Am reading a couple of values from a txt file and store them in a table. The
first line of the txt file is read well and saved. When the program reads
the second line, it displays the errors listed down.
Here is a method am using:
public boolean addUser(
String ID,
String Password,
String lastName,
String firstName)
throws SQLException, ClassNotFoundException, IOException {
conn = Connect.getConnection();
while (in.ready()) {
String line = in.readLine();
st = new StringTokenizer(line);
while (st.hasMoreTokens()){
myID = st.nextToken();
myPassword = st.nextToken();
mylastName = st.nextToken();
myfirstName = st.nextToken();
ID = myID;
Password = myPassword;
lastName = mylastName;
firstName = myfirstName;
String sql = "INSERT INTO supervisor " +
"(superv_id, superv_pass, superv_lastname,
superv_firstname)" +
"VALUES (?,?,?,?)";
prep = conn.prepareStatement(sql);
prep.setString(1, ID);
prep.setString(2, Password);
prep.setString(3, lastName);
prep.setString(4, firstName);
prep.executeUpdate();
conn.close();
}
}
return true;
}
Error:
Exception in thread "main" org.postgresql.util.PSQLException: An I/O error
occured while sending to the backend.
Exception: java.io.IOException: Stream closed
Stack Trace:
java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:38)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:151)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)
at org.postgresql.core.PGStream.flush(PGStream.java:507)
at
org.postgresql.core.v3.QueryExecutorImpl.sendSync(QueryExecutorImpl.java:675)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:190)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
at prototype.PopulatingDB.addUser(PopulatingDB.java:68)
at prototype.PopulatingDB.<init>(PopulatingDB.java:29)
at prototype.PopulatingDB.main(PopulatingDB.java:77)
End of Stack Trace
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
at prototype.PopulatingDB.addUser(PopulatingDB.java:68)
at prototype.PopulatingDB.<init>(PopulatingDB.java:29)
at prototype.PopulatingDB.main(PopulatingDB.java:77)
Java Result: 1
_________________________________________________________________
Tell MSN about your most memorable emails! http://www.emailbritain.co.uk/