// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package db2sp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DB2Supp {
    public static void Testjavasp(int f1, String f2) throws SQLException {
        Connection con = DriverManager.getConnection("jdbc:default:connection");
        PreparedStatement pstmt = con.prepareStatement("INSERT INTO t1 VALUES(?,?)");
        pstmt.setInt(1, f1);
        pstmt.setString(2, f2);
        pstmt.execute();
        pstmt.close();
        con.close();
    }
    private static short isprime(int ival) {
        for(int i = 2; i <= Math.sqrt(ival); i++) {
            if(ival % i == 0) {
                return 0;
            }
        }
        return 1;
    }
    public static void Insertsp(int ival, String sval) throws SQLException {
        Connection con = DriverManager.getConnection("jdbc:default:connection");
        PreparedStatement pstmt = con.prepareStatement("INSERT INTO qpi(ival,isprime,sval) VALUES(?,?,?)");
        pstmt.setInt(1, ival);
        pstmt.setShort(2, isprime(ival));
        pstmt.setString(3, sval);
        pstmt.execute();
        pstmt.close();
        con.close();
    }
}
