Created
September 20, 2016 14:29
-
-
Save rhulha/6ca3ff1cfacd8e32d21a8d4e2dbeae7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import FairCom.CtreeDb.*; | |
| import FairCom.CtreeDb.Types.*; | |
| import java.util.Calendar; | |
| /** | |
| * Java + JTDB Hello world Example | |
| * | |
| */ | |
| public class App { | |
| public static void main(String[] args) { | |
| try { | |
| /**** Connect to c-treeACE Server ****/ | |
| CTSession MySession = new CTSession(SESSION_TYPE.CTREE); | |
| MySession.Logon("FAIRCOMS", "ADMIN", "ADMIN"); | |
| /**** Open table ****/ | |
| // if collection doesn't exists, we need to create it | |
| CTTable MyTable = new CTTable(MySession); | |
| try { | |
| MyTable.Open("user", OPEN_MODE.NORMAL); | |
| } catch (CTException E) { | |
| MyTable.AddField("name", FIELD_TYPE.CHARS, 20); | |
| MyTable.AddField("age", FIELD_TYPE.INT4, 4); | |
| MyTable.AddField("createdDate", FIELD_TYPE.DATE, 4); | |
| /**** Create table ****/ | |
| MyTable.Create("user", CREATE_MODE.NORMAL); | |
| /**** Open table ****/ | |
| MyTable.Open("user", OPEN_MODE.NORMAL); | |
| } | |
| /**** Insert ****/ | |
| // create a record to store key and value | |
| CTRecord MyRecord = new CTRecord(MyTable); | |
| MyRecord.Clear(); | |
| MyRecord.SetFieldAsString("name", "mkyong"); | |
| MyRecord.SetFieldAsInt("age", 30); | |
| MyRecord.SetFieldAsCalendar("createdDate", Calendar.getInstance()); | |
| MyRecord.Write(); | |
| /**** Find and display ****/ | |
| MyRecord.Clear(); | |
| MyRecord.SetFieldAsString("name", "mkyong"); | |
| MyRecord.RecordSetOn(6); | |
| boolean found = MyRecord.First(); | |
| while( found ) { | |
| System.out.println(MyRecord.GetFieldAsString("name")); | |
| found = MyRecord.Next(); | |
| } | |
| /**** Done ****/ | |
| System.out.println("Done"); | |
| } catch (CTException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment