problems with insert into and char "

Hi all!

I amb doing a program wich interacts with a .mdb database. All works fine but excepts for one thing:

More or less like this is my database table:

table liniaAlbara{

PK idLinia ( auto)

idAlbara

worker

workstation

workDone

hours

date

}

if I do the next query with microsoft access all works fine :

insert into liniaAlbara (idAlbara,worker,workstation,workDone,hours,date) values(19,32,140,"mane d'en tou",4,#16/07/2007#)

everything is ok. The problem is when I do this from my java applicattion.

I have som JTextFields to get each field. To make the sql query I do this:

queryHead = "insert into liniaAlbara (idAlbara,worker,workstation,workDone,hours,date) values(";

Character c = new Character(");

query = queryHead+idAlbara+","+idTreballador+","+idObra+","+c+feina+c+","+hores+",#"+data+"#)";

If I do a System.out.println(query);

I see this:

insert into liniaAlbara (idAlbara,worker,workstation,workDone,hours,date) values(19,32,140,"mane d'en tou",4,#16/07/2007#)

wich seem to be ok, but when I do this:

try {

crida = connexio.createStatement();

crida.executeUpdate(query);

} catch (SQLException ex) {

ex.printStackTrace();

}

I get this error:

java.sql.SQLException: [Microsoft][Controlador ODBC Microsoft Access] Pocos parmetros. Se esperaba 1.

at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)

at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)

at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)

at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)

at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)

..too few parameters, expecting 1.

The problem is that I can't use " " to insert text, only I can use ' , but the problem then is if write something with this character everything crash.

what's wrong?

thanks!

}

[2057 byte] By [Asaaka] at [2007-11-27 10:44:04]
# 1

Use PreparedStatement and its set..... methods, and your problem will be solved.

masijade.a at 2007-7-28 20:04:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...