Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. Calendar cal = Calendar.getInstance();
  2.         int year = cal.get(Calendar.YEAR);    // The current year as an int
  3.         int month = (cal.get(Calendar.MONTH) + 1);
  4.        
  5.         String tahun_ntpd = Integer.toString(year);
  6.         String bulan_ntpd = Integer.toString(month);
  7.        
  8.         String test="";
  9.         try{  
  10.             Class.forName("com.mysql.jdbc.Driver");  
  11.             Connection con=DriverManager.getConnection(  
  12.             "jdbc:mysql://localhost:3306/masterpendapatan","root","");  
  13.             //here sonoo is database name, root is username and password  
  14.             Statement stmt=con.createStatement();  
  15.             ResultSet rs=stmt.executeQuery("select * from ntpd where year = '" + year +"' and month = '" + month +"'");  
  16.            
  17.             //PreparedStatement stmt = con.prepareStatement("select * from ntpd where year = '" + tahun_ntpd +"' and month = '" + bulan_ntpd +"'");    
  18.            
  19.             //ResultSet rs = stmt.executeQuery();
  20.             //System.out.println(rs);
  21.             while(rs.next())  
  22.             System.out.println(year);
  23.             test += rs.getString(2);
  24.             con.close();  
  25.             }catch(Exception e){
  26.                 log.error("Some exception has been thrown", e);
  27.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement