Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package routines;
- import java.sql.*;
- import java.util.Calendar;
- /*
- * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
- * it must be before the "{talendTypes}" key.
- *
- * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
- * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
- * Short
- *
- * 3. {Category} define a category for the Function. it is required. its value is user-defined .
- *
- * 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]
- *
- * <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
- * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
- * added. you can have many parameters for the Function.
- *
- * 5. {example} gives a example for the Function. it is optional.
- */
- public class GenerateNtpd {
- /**
- * helloExample: not return value, only print "hello" + message.
- *
- *
- * {talendTypes} String
- *
- * {Category} User Defined
- *
- * {param} string("world") input: The string need to be printed.
- *
- * {example} helloExemple("world") # hello world !.
- */
- public static void helloExample(String message) {
- if (message == null) {
- message = "World"; //$NON-NLS-1$
- }
- System.out.println("Hello " + message + " !"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- /**
- * kodeSkrd: return skrd.
- *
- *
- * {talendTypes} String
- *
- * {Category} User Defined
- *
- * {param} string("1234,1") input: The string need to be printed.
- *
- * {example} kodeSkrd("1234,1") # 1234,1;1234,2.
- */
- public static String kodeSkrd(String kodeskrd){
- String kode = "", wilayah = "";
- System.out.println(kodeskrd);
- Calendar now = Calendar.getInstance(); // Gets the current date and time
- int year = now.get(Calendar.YEAR) % 100; // The current year as an int
- int month = (now.get(Calendar.MONTH) + 1);
- String comma_sepetard="", counter="";
- int ntpd = 0,year_db=0, month_db=0;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/masterpendapatan","root","");
- //here sonoo is database name, root is username and password
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("select * from ntpd where year = "+year+" and month ="+month);
- while(rs.next()){
- System.out.println(rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4));
- ntpd += rs.getInt(4);
- year_db += rs.getInt(2);
- month_db += rs.getInt(3);
- }
- if(ntpd == 0){
- System.out.println("2");
- Statement stmt2=con.createStatement();
- stmt2.executeUpdate("INSERT INTO ntpd (year, month, counter) values ("+year+","+month+",1)");
- }
- String[] array = kodeskrd.split("\\;");
- kode += array[0];
- wilayah += array[1];
- System.out.println(kode);
- if(kode.length() == 14){
- int i = 1;
- for(String s : array) {
- Integer start = new Integer(ntpd);
- Integer end = start + i; // end == 10;
- counter = String.format("%06d", end);
- comma_sepetard += "";
- comma_sepetard += s+","+wilayah+(year_db+month_db+counter);
- comma_sepetard += ";";
- ++i;
- }
- }else{
- /*String[] array = kodeskrd.split("\\;");
- String parent = array[0];
- String[] child = parent.split("\\,");*/
- System.out.println("aaa");
- }
- /*int i = 1;
- for(String s : array) {
- Integer start = new Integer(ntpd);
- Integer end = start + i; // end == 10;
- counter = String.format("%06d", end);
- comma_sepetard += "";
- comma_sepetard += s+","+wilayah+(year_db+month_db+counter);
- comma_sepetard += ";";
- ++i;
- }*/
- Statement stmt1=con.createStatement();
- stmt1.execute("update ntpd set counter = "+counter+" where year = "+year+" and month ="+month);
- con.close();
- }catch(Exception e){ System.out.println(e);}
- return comma_sepetard;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement