Hi !
First of all if this query should rather have gone to a different
forum. Pardon me if I am at wrong location.
I am trying to write a conduit in Java using CDKJ. I have not done
anything extra - only picked up a sample RDBMS conduit from there and
add my functionality into it. I am reading the records from an Access
database table and trying to put them in a Palm database ( pdb ).
When I run the hotsyncing, the records from the Access database do go
in palm pdb, but when I try to view the records on Palm device, I
dont see anything.
What could be going wrong ? I am doubting the implementation of
my "writeData(DataOutputStream out)" and/or "readData(DataInputStream
in)" methods of the class "ContactRecord" [ please see below ].
Am I doing something stupid in the conduit code or I need to go back
and scrutinise my palm application ( that displays the records from
the .pdb file ) ?
Please comment.
///////////////////////////////Conduit Code follows////////////////
/**
* This class acts as a catalyst between the ContactConduit and the
Access Database.
*/
public class ContactRecord extends palm.conduit.AbstractRecord {
private int m_iContactID ;
private String m_sContactName;
private String m_sContactPhone;
public void setContactID( int contactId ) {
m_iContactID = contactId ;
}
public void setContactName( String name ) {
m_sContactName = name ;
}
public void setContactPhone( String phone ) {
m_sContactPhone = phone ;
}
//public String getContactID() {
public int getContactID() {
return m_iContactID ;
}
public String getContactName() {
return m_sContactName ;
}
public String getContactPhone() {
return m_sContactPhone ;
}
public void writeData(DataOutputStream out) throws IOException{
// for debugging purpose, this file is used
FileOutputStream fileOut = new FileOutputStream
( "C:\\sanju\\myfile.txt" );
ObjectOutputStream objOut = new ObjectOutputStream(
fileOut );
// ContactID
objOut.writeInt(m_iContactID);
out.writeInt(m_iContactID);
out.write(0);
// ContactName
if (m_sContactName != null) {
objOut.writeObject( (String)m_sContactName );
out.write(m_sContactName.getBytes());
out.write(0);
}
// ContactPhone
if (m_sContactPhone != null) {
objOut.writeObject( (String)m_sContactPhone );
out.write(m_sContactPhone.getBytes());
out.write(0);
}
fileOut.close();
objOut.close();
}
public void readData(DataInputStream in) throws IOException{
m_iContactID = in.readInt();
m_sContactName = readCString(in);
m_sContactPhone = readCString(in);
Log.AddEntry("[ ContactRecord ] : [ readData() ] : "
+ m_iContactID , Log.TEXT, false);
Log.AddEntry("[ ContactRecord ] : [ readData() ] : "
+ m_sContactName , Log.TEXT, false);
Log.AddEntry("[ ContactRecord ] : [ readData() ] : "
+ m_sContactPhone , Log.TEXT, false);
File myFile = new File( "C:\\sanju\\myfile.txt" );
FileOutputStream fileOut = new FileOutputStream
( "C:\\sanju\\myfile.txt" );
}
public String toString() {
return "Contacts ***** record: " ;
}
public String toFormattedString() {
return " **** CONTACTS RECORD ****** ";
}
}
/*********************************************************************
***************/
// This class is in different file on my machine
public class ContactConduit implements Conduit {
Vector addresses;
Connection connection;
ContactRecord address;
int db;
public void open(SyncProperties props) {
Vector addresses;
Record record;
Log.startSync();
Log.AddEntry("[ ContactConduit ] : [ open() ] : [ Inside the
open method. ]", Log.TEXT, false);
try {
db = SyncManager.openDB("SHRIRANG", 0,
SyncManager.OPEN_READ |
SyncManager.OPEN_WRITE | SyncManager.OPEN_EXCLUSIVE);
Log.AddEntry("[ ContactConduit ] : [ open() ] : [ The
remote database was opened . db = " + db + " ] ", Log.TEXT, false);
getConnection();
addresses = selectAddresses();
SyncManager.closeDB(db);
Log.AddEntry("CONTACT - INVENTORY conduit was
successfully executed", Log.TEXT, false);
Log.endSync();
} catch (Throwable t) {
t.printStackTrace();
Log.abortSync();
}
}
public void getConnection()throws SQLException,
ClassNotFoundException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection
("jdbc:odbc:contacts");
Log.AddEntry("[ ContactConduit ] : [ open() ] : [
connected with the ACCESS database ]", Log.TEXT, false);
}
public Vector selectAddresses() throws SQLException{
Log.AddEntry("[ ContactConduit ] : [ selectAddresses
() ] : [ Inside the selectAddresses() method. ]", Log.TEXT, false);
ResultSet resultset;
Record record;
Statement statement, statement2;
int l_sID = 0;
statement = connection.createStatement();
resultset = statement.executeQuery("select * from
ContactPC "); // where ISNEW = 'Y'");
addresses = new Vector();
while(resultset.next()) { //there are more
address records
address = new ContactRecord();
l_sID = resultset.getInt("ID");
address.setId( l_sID );
address.setCategoryIndex
(resultset.getInt("CATEGORYINDEX"));
address.setContactID(resultset.getInt
("ContactID"));
address.setContactName
(resultset.getString("ContactName"));
address.setContactPhone
(resultset.getString("ContactPhone"));
try{
SyncManager.writeRec(db,
(Record) address);
Log.AddEntry("[
ContactConduit ] : [ selectAddresses() ] : [ After Invocation of the
writeRec() method ]", Log.TEXT, false);
}
catch(Throwable t){
Log.AddEntry(t + "
ContactConduit : Record with ID = " + l_sID
+ " could not be added to the
device", 0, false);
}
addresses.addElement(address);
}// end while
connection.commit();
connection.close();
return addresses;
}
public String name() {
return "ContactConduit";
}
public int configure(ConfigureConduitInfo info) {
return 0;
}
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/