import java.sql.*;
import JP.co.Hitachi.soft.HiRDB.pdjpp.runtime.*;
//Iterator (cursor) declaration
#sql iterator Pos(int,HiRDBCHAR(10),HiRDBNCHAR(5),HiRDBDECIMAL(10,5));
public class sample1{
public static void main(String args[]){
//Connection and table creation
try{
#sql{CONNECT}; //Refer to the client environment variables and connect.
#sql{CREATE TABLE SAMPLE1(c1 int,c2 char(10),c3 nchar(5),c4 decimal(10,5))};
}catch(SQLException e){System.out.println(e.getMessage());};
//Insert data
try{
int InInt = 100;
HiRDBCHAR InChar = new HiRDBCHAR("CHAR");
HiRDBNCHAR InNchar = new HiRDBNCHAR("NCHAR");
HiRDBDECIMAL InDecimal = new HiRDBDECIMAL("12345.678");
#sql{INSERT INTO SAMPLE1 VALUES(:InInt,:InChar,:InNchar,:InDecimal)};
#sql{COMMIT};
}catch(SQLException e){System.out.println(e.getMessage());};
//Retrieve data (single-row retrieval)
try{
//Declare output variables
int OutInt = 0;
HiRDBCHAR OutChar = new HiRDBCHAR(10);
HiRDBNCHAR OutNchar = new HiRDBNCHAR(5);
HiRDBDECIMAL OutDecimal = new HiRDBDECIMAL(10,5);
#sql {SELECT * INTO :OutInt,:OutChar,:OutNchar,:OutDecimal FROM SAMPLE1};
System.out.println("c1="+ OutInt +" c2="+ OutChar.getString() +
" c3="+ OutNchar.getString() + " c4="+ OutDecimal.getString());
}catch(SQLException e){System.out.println(e.getMessage());};
try{#sql{DISCONNECT};}catch(SQLException e){System.out.println(e.getMessage());}
}
} |