my programme add only one record and then throw exception
file://code
public class Worker {
private Connection AccessConector;
private Connection InterbaseConector;
public Worker() {
}
public void CreateConnectionToAccess(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
AccessConector=DriverManager.getConnection("jdbc:odbc:address","","");
}catch(Exception e){
e.printStackTrace();
}
}
public void CreateConnectionToInterbase(){
try{
Class.forName("interbase.interclient.Driver");
Properties conninfo=new Properties();
conninfo.put("user","user1");
conninfo.put("password","pass1");
conninfo.put("charSet","Cp1251");
InterbaseConector=DriverManager.getConnection("jdbc:interbase://localhost/d:
/1/adress_cp1251.gdb",conninfo);
}catch(Exception e){
e.printStackTrace();
}
}
public void migrate(){
int count=1;
try{
Statement staccess=AccessConector.createStatement();
Statement stinterbase=InterbaseConector.createStatement();
ResultSet rs=staccess.executeQuery("select * from Предприятия");
while(rs.next()){
System.out.println("added record: "+count);
stinterbase.executeUpdate("insert into address "+
"(id,id_groups,enterprisename,chiefposition,chiefname,index_number,"+
"region,sregion,town,address) values ("+count+",1,'"+
rs.getString(2)+"','"+
rs.getString(3)+"','"+
rs.getString(4)+"','"+
rs.getString(5)+"','"+
rs.getString(6)+"','"+
rs.getString(7)+"','"+
rs.getString(8)+"','"+
rs.getString(9)+"');");
AccessConector.commit();
count++;
}
}catch(Exception e){
e.printStackTrace();
}
}
file://exception
added record: 1
added record: 2
interbase.interclient.SQLException: [interclient][interbase] Dynamic SQL
Error
SQL error code = -104
Unexpected end of command
at interbase.interclient.RecvMessage.createSQLException(Unknown Source)
at interbase.interclient.RecvMessage.makeSQLException(Unknown Source)
at interbase.interclient.RecvMessage.get_EXCEPTIONS(Unknown Source)
at interbase.interclient.Statement.remote_EXECUTE_UPDATE_STATEMENT(Unknown
Source)
at interbase.interclient.Statement.executeUpdate(Unknown Source)
at migration.Worker.migrate(Worker.java:74)
at migration.App.main(App.java:18)
Silvio Bierman
"Pavel L.Yatsuk" <er...@astral.ntu-kpi.kiev.ua> wrote in message
news:ahlop1$2b79$1...@igloo.uran.net.ua...
: Hi ALL!!!
:
:
:
This line looks suspicious - there is no not to commit anything, as you
are only reading from the AccessConnection. Maybe this closes the result
set?
> count++;
> }
> }catch(Exception e){
> e.printStackTrace();
> }
And, as another poster suggested, java.sql.PreparedStatement is really
your friend!
HTH
Andreas