Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
2,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.86 KB | None | 0 0
  1. package routines;
  2.  
  3. import java.sql.*;
  4. import java.util.Calendar;
  5. /*
  6.  * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
  7.  * it must be before the "{talendTypes}" key.
  8.  *
  9.  * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
  10.  * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
  11.  * Short
  12.  *
  13.  * 3. {Category} define a category for the Function. it is required. its value is user-defined .
  14.  *
  15.  * 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]
  16.  *
  17.  * <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
  18.  * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
  19.  * added. you can have many parameters for the Function.
  20.  *
  21.  * 5. {example} gives a example for the Function. it is optional.
  22.  */
  23. public class GenerateNtpd {
  24.    
  25.     /**
  26.      * helloExample: not return value, only print "hello" + message.
  27.      *
  28.      *
  29.      * {talendTypes} String
  30.      *
  31.      * {Category} User Defined
  32.      *
  33.      * {param} string("world") input: The string need to be printed.
  34.      *
  35.      * {example} helloExemple("world") # hello world !.
  36.      */
  37.     public static void helloExample(String message) {
  38.         if (message == null) {
  39.             message = "World"; //$NON-NLS-1$
  40.         }
  41.         System.out.println("Hello " + message + " !"); //$NON-NLS-1$ //$NON-NLS-2$
  42.     }
  43.    
  44.     /**
  45.      * kodeSkrd: return skrd.
  46.      *
  47.      *
  48.      * {talendTypes} String
  49.      *
  50.      * {Category} User Defined
  51.      *
  52.      * {param} string("1234,1") input: The string need to be printed.
  53.      *
  54.      * {example} kodeSkrd("1234,1") # 1234,1;1234,2.
  55.      */
  56.     public static String kodeSkrd(String kodeskrd){
  57.        
  58.         String kode = "", wilayah = "";
  59.         System.out.println(kodeskrd);
  60.        
  61.         Calendar now = Calendar.getInstance();   // Gets the current date and time
  62.         int year = now.get(Calendar.YEAR) % 100;      // The current year as an int
  63.         int month = (now.get(Calendar.MONTH) + 1);
  64.        
  65.         String comma_sepetard="", counter="";
  66.         int ntpd = 0,year_db=0, month_db=0;
  67.        
  68.         try{  
  69.             Class.forName("com.mysql.jdbc.Driver");  
  70.             Connection con=DriverManager.getConnection(  
  71.             "jdbc:mysql://localhost:3306/masterpendapatan","root","");  
  72.             //here sonoo is database name, root is username and password  
  73.             Statement stmt=con.createStatement();  
  74.             ResultSet rs=stmt.executeQuery("select * from ntpd where year = "+year+" and month ="+month);
  75.            
  76.            
  77.             while(rs.next()){  
  78.                
  79.                 System.out.println(rs.getString(2)+"  "+rs.getString(3)+"  "+rs.getString(4));
  80.                 ntpd += rs.getInt(4);
  81.                 year_db += rs.getInt(2);
  82.                 month_db += rs.getInt(3);
  83.             }
  84.            
  85.             if(ntpd == 0){
  86.                 System.out.println("2");
  87.                 Statement stmt2=con.createStatement();  
  88.                 stmt2.executeUpdate("INSERT INTO ntpd (year, month, counter) values ("+year+","+month+",1)");
  89.             }
  90.            
  91.             String[] array = kodeskrd.split("\\;");
  92.             kode += array[0];
  93.             wilayah += array[1];
  94.             System.out.println(kode);
  95.             if(kode.length() == 14){
  96.                
  97.                 int i = 1;
  98.                 for(String s : array) {
  99.                     Integer start = new Integer(ntpd);
  100.                     Integer end = start + i; // end == 10;
  101.                     counter = String.format("%06d", end);
  102.                    
  103.                     comma_sepetard += "";
  104.                     comma_sepetard += s+","+wilayah+(year_db+month_db+counter);
  105.                     comma_sepetard += ";";
  106.                    
  107.                     ++i;
  108.                 }
  109.             }else{
  110.                 /*String[] array = kodeskrd.split("\\;");
  111.                
  112.                 String parent = array[0];
  113.                 String[] child = parent.split("\\,");*/
  114.                 System.out.println("aaa");
  115.                
  116.             }
  117.            
  118.             /*int i = 1;
  119.             for(String s : array) {
  120.                 Integer start = new Integer(ntpd);
  121.                 Integer end = start + i; // end == 10;
  122.                 counter = String.format("%06d", end);
  123.                
  124.                 comma_sepetard += "";
  125.                 comma_sepetard += s+","+wilayah+(year_db+month_db+counter);
  126.                 comma_sepetard += ";";
  127.                
  128.                 ++i;
  129.             }*/
  130.            
  131.             Statement stmt1=con.createStatement();  
  132.             stmt1.execute("update ntpd set counter = "+counter+" where year = "+year+" and month ="+month);
  133.            
  134.            
  135.            
  136.             con.close();  
  137.             }catch(Exception e){ System.out.println(e);}  
  138.        
  139.        
  140.        
  141.         return comma_sepetard;
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement