Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with Interbase.

2 views
Skip to first unread message

Pavel L.Yatsuk

unread,
Jul 24, 2002, 4:33:24 AM7/24/02
to
Hi ALL!!!
I have task to copy data from access to Interbase.
and have problem

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

unread,
Jul 24, 2002, 6:02:12 AM7/24/02
to
Use prepared statements, at least for the insert. Inserting literal data in
an SQL statement can easily produce invalid SQL as in your case.

Silvio Bierman

"Pavel L.Yatsuk" <er...@astral.ntu-kpi.kiev.ua> wrote in message
news:ahlop1$2b79$1...@igloo.uran.net.ua...
: Hi ALL!!!

:
:
:


Andreas Wollschlaeger

unread,
Jul 24, 2002, 7:32:22 AM7/24/02
to
Pavel L.Yatsuk wrote:
> Hi ALL!!!
> I have task to copy data from access to Interbase.
> and have problem
>
> my programme add only one record and then throw exception
>
> file://code
> public class Worker {
>
> private Connection AccessConector;
>
> 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,'"+
> ...
> AccessConector.commit();
^^^^^^^^^^^^^^^^^^^^^^^^

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


0 new messages