Advertisement
Guest User

Untitled

a guest
May 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.51 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. /**
  7. *
  8. * @author joel
  9. */
  10. /*
  11. * To change this license header, choose License Headers in Project Properties.
  12. * To change this template file, choose Tools | Templates
  13. * and open the template in the editor.
  14. */
  15. package Com;
  16.  
  17. import java.io.Serializable;
  18. import java.sql.Connection;
  19. import java.sql.Driver;
  20. import java.sql.DriverManager;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.sql.SQLException;
  24. import java.sql.Statement;
  25. import java.text.DateFormat;
  26. import java.text.ParseException;
  27. import java.text.SimpleDateFormat;
  28. import java.util.AbstractList;
  29. import java.util.ArrayList;
  30. import static java.util.Collections.list;
  31. import java.util.Enumeration;
  32. import java.util.List;
  33.  
  34.  
  35. /**
  36. *
  37. * @author joel
  38. */
  39. public class dbmanager implements Serializable {
  40.  
  41. private static Connection connection = null;
  42. private Statement statement = null;
  43. private PreparedStatement preparedStatement = null;
  44. private ResultSet resultSet = null;
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. public static void insertrequest(String begin ,String end ) throws SQLException {
  52. int i= 0;
  53.  
  54. try {
  55. Class.forName("org.apache.derby.jdbc.ClientDriver");
  56. } catch(ClassNotFoundException e) {
  57. System.out.println("Class not found "+ e);
  58. }
  59. try {
  60.  
  61. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  62. PreparedStatement stm = connection.prepareStatement( "INSERT INTO PERSON(PERSONID,FIRSTNAME,LASTNAME,ADDRESS,CITY,CONFIRM1,CONFIRM2,CONFIRM3) VALUES (?,?,?,?,?,?,?,?)" );
  63. stm.setInt(1, 123456);
  64. stm.setString(2, "NGatouo");
  65. stm.setString(3, "Joel");
  66. stm.setString(4,begin);
  67. stm.setString(5,end);
  68. stm .setBoolean(6, true);
  69. stm .setBoolean(7, false);
  70. stm .setBoolean(8, false);
  71. i = stm.executeUpdate();
  72. } catch (Exception e) {
  73. System.out.println("error:ddddd ");
  74. }
  75.  
  76. // connection.toString();
  77. //
  78. //
  79. // System.out.print( connection.toString());
  80. // System.out.print( connection.toString());
  81. System.out.print(end);
  82. System.out.print(i+" the number of element add ");
  83.  
  84. // System.out.print(i+" record sont state inseriti");
  85. return ;
  86.  
  87. }
  88. public static void getrequest(ArrayList<String> out ,ArrayList<Boolean> bool) throws SQLException {
  89. int i= 0;
  90.  
  91. try {
  92. Class.forName("org.apache.derby.jdbc.ClientDriver");
  93. } catch(ClassNotFoundException e) {
  94. System.out.println("Class not found "+ e);
  95. }
  96. try {
  97.  
  98. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  99. PreparedStatement stm = connection.prepareStatement( "select LASTNAME , FIRSTNAME, ADDRESS,CITY, CONFIRM1,CONFIRM2,CONFIRM3 from SA.PERSON where PERSONID = 123456" );
  100. ResultSet rs = stm.executeQuery();
  101. if (rs.next()) {
  102.  
  103. out.add(rs.getString(1));
  104. out.add(rs.getString(2));
  105. out.add(rs.getString(3));
  106. out.add(rs.getString(4));
  107. bool.add(rs.getBoolean(5));
  108. bool.add(rs.getBoolean(6));
  109. bool.add(rs.getBoolean(7));
  110.  
  111. }
  112.  
  113. } catch (Exception e) {
  114. System.out.println("error:ddddd ");
  115. }
  116.  
  117. return ;
  118.  
  119. }
  120. public static void rejectrequest() throws SQLException {
  121. int i= 0;
  122.  
  123. try {
  124. Class.forName("org.apache.derby.jdbc.ClientDriver");
  125. } catch(ClassNotFoundException e) {
  126. System.out.println("Class not found "+ e);
  127. }
  128. try {
  129.  
  130. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  131. PreparedStatement stm = connection.prepareStatement( "UPDATE PERSON SET CONFIRM1 = false WHERE PERSONID = 123456" );
  132. int rs = stm.executeUpdate();
  133.  
  134.  
  135.  
  136. } catch (Exception e) {
  137. System.out.println("error:ddddd ");
  138. }
  139.  
  140. return ;
  141.  
  142. }
  143. public static void acceptrequest() throws SQLException {
  144. int i= 0;
  145.  
  146. try {
  147. Class.forName("org.apache.derby.jdbc.ClientDriver");
  148. } catch(ClassNotFoundException e) {
  149. System.out.println("Class not found "+ e);
  150. }
  151. try {
  152.  
  153. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  154. PreparedStatement stm = connection.prepareStatement( "UPDATE PERSON\n" +
  155. "SET CONFIRM1 = true , CONFIRM2 = true WHERE PERSONID = 123456" );
  156. int rs = stm.executeUpdate();
  157.  
  158.  
  159.  
  160. } catch (Exception e) {
  161. System.out.println("error:ddddd ");
  162. }
  163.  
  164. return ;
  165.  
  166. }
  167.  
  168. public static void InsertSystem() throws SQLException {
  169. int i= 0;
  170.  
  171. try {
  172. Class.forName("org.apache.derby.jdbc.ClientDriver");
  173. } catch(ClassNotFoundException e) {
  174. System.out.println("Class not found "+ e);
  175. }
  176. try {
  177.  
  178. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  179. PreparedStatement stm = connection.prepareStatement( "UPDATE PERSON SET CONFIRM3 = true WHERE PERSONID = 123456" );
  180. int rs = stm.executeUpdate();
  181.  
  182.  
  183.  
  184. } catch (Exception e) {
  185. System.out.println("error:ddddd ");
  186. }
  187.  
  188. return ;
  189.  
  190. }
  191.  
  192.  
  193. public static void UpdateTime(int time) throws SQLException {
  194.  
  195. try {
  196. Class.forName("org.apache.derby.jdbc.ClientDriver");
  197. } catch(ClassNotFoundException e) {
  198. System.out.println("Class not found "+ e);
  199. }
  200. try {
  201.  
  202. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  203. PreparedStatement stm = connection.prepareStatement( "UPDATE PERSONS SET PERSONID = ? " );
  204. stm.setInt(1, time);
  205. int rs = stm.executeUpdate();
  206. } catch (Exception e) {
  207. System.out.println("error:ddddd ");
  208. }
  209.  
  210. return ;
  211.  
  212. }
  213. public static int getTime() throws SQLException {
  214. int i= 0;
  215.  
  216. try {
  217. Class.forName("org.apache.derby.jdbc.ClientDriver");
  218. } catch(ClassNotFoundException e) {
  219. System.out.println("Class not found "+ e);
  220. }
  221. try {
  222.  
  223. connection = DriverManager.getConnection("jdbc:derby://localhost:1527/STB","sa","sa");
  224. PreparedStatement stm = connection.prepareStatement( "SELECT PERSONID FROM PERSONS" );
  225. ResultSet rs = stm.executeQuery();
  226. if (rs.next()) {
  227.  
  228. i = rs.getInt(1);
  229.  
  230.  
  231. }
  232.  
  233. } catch (Exception e) {
  234. System.out.println("error:ddddd ");
  235. }
  236.  
  237. return i ;
  238.  
  239. }
  240.  
  241.  
  242. public static int convertTime(String str1,String str2){
  243. int diffHours = 0 ;
  244. int diffInDays = 0 ;
  245. long diff = 0 ;
  246. java.util.Date d1 = null;
  247. java.util.Date d2 = null;
  248. DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
  249. System.out.print(str1 +" questo è l'heure reduit alla fin ");
  250. System.out.print(str2 +" questo è l'heure reduit alla fin ");
  251. try {
  252. d1 = formatter.parse(str1);
  253. d2 = formatter.parse(str2);
  254. } catch (ParseException e) {
  255. e.printStackTrace();
  256. }
  257.  
  258. diff = d2.getTime() - d1.getTime() ;
  259. diffInDays = (int) (( d2.getTime() - d1.getTime() ) / (1000 * 60 * 60 * 24)) +1;
  260. diffHours =(int)((diff / (60 * 60 * 1000)) +24) - 16*diffInDays ;
  261.  
  262. System.out.print(diffHours +" questo è l'heure reduit alla fin ");
  263.  
  264. return diffHours ;}
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement