Re: Using dataexpress with insert or prepared statements


2003-07-26 09:07:22 AM
jbuilder9
Rudy wrote:
Quote
Hi,
I would like to know how to either 1) incorporate prepared statements
using dataexpress components or 2) how to using a simple INSERT statement
using data express or how INSERT statements are written using dataModules
etc??

Thanks in advance
Rudy
You can use the Borland Database Components, but to be honest with you, I
have the ParameterRow stuff. so I simply create my PreparedStatements
(which I do BTW), from the Database Component direct.
Example
package net.clc.demo
import java.sql.*;
import com.borland.dx.dataset.*;
import com.borland.dx.sql.dataset.*;
public class Demo {
MyDataModule dm=MyDataModule.getDataModule();
Database db= dm.getDatabase();
public boolean runSomePreparedStatement(MyClass aClass){
boolean result=true; //assume true
String sql="Inser into SomeTable(ID,Name,Address,City, State)
Values(?,?,?,?,?)";
try {
PreparedStatement ps=db.createPreparedStatement(sql);
ps.setInt(1,aClass.getID());
ps.setString(2,aClass.getName());
ps.setString(3,aClass.getAddress());
ps.setString(4,aClass.getCity());
ps.setString(5,aClass.getState());
ps.executeUpdate();
ps.close();
}
catch (Exception ex) {
result=false;
ex.printStackTrace();
}
return result;
}
}