Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. package main.java;
  2.  
  3. import java.io.*;
  4. import java.sql.*;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. public class DB2Test{
  10. public Connection getConnection() throws ClassNotFoundException, SQLException
  11. {
  12. Class. forName ( "COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver" );
  13. Connection connection =
  14. DriverManager.getConnection("jdbc:db2://dashdb-txn-sbox-yp-dal09-03.services.dal.bluemix.net:50001/BLUDB:sslConnection=true;","zdp02898","92f7w610c@39xrsv");
  15.  
  16. System. out .println( "From DAO, connection obtained " );
  17. return connection;
  18. }
  19. public void insertData(Connection conn)
  20. {
  21. Statement stmt;
  22. try
  23. {
  24. stmt = conn.createStatement();
  25. stmt.executeUpdate("insert into events (shortname, location, begindate, enddate, contact) values('shortname1', 'location1','begindat1e','e1nddate','con1tact')");
  26. stmt.close();
  27. conn.close();
  28. }
  29. catch (Exception e)
  30. {
  31. e.printStackTrace();
  32. }
  33. }
  34. public Map<String,String> pullData(Connection conn, String identifier)
  35. {
  36. ResultSet rs;
  37. Statement stmt;
  38. String pullquery = "Select * from sponsorshipTable where EID=" + identifier;
  39. Map<String, String> data = new HashMap<String, String>();
  40. try
  41. {
  42. BufferedReader textreader = new BufferedReader(new FileReader("DB2Map.txt"));
  43. int MapLines = countLines("DB2Map.txt");
  44. stmt = conn.createStatement();
  45. System.out.println("heh");
  46. System.out.println(stmt);
  47. System.out.println(conn);
  48. rs = stmt.executeQuery(pullquery);
  49. System.out.println("here");
  50. rs.next();
  51. System.out.println(rs.getString(2));
  52. int counter = 1;
  53. while (counter < MapLines + 1){
  54. String line = textreader.readLine();
  55. String temp = rs.getString(counter);
  56. System.out.println(temp);
  57. if ((temp == null) || temp.equals("null")){
  58. data.put(line, "");
  59. }
  60. else{
  61. data.put(line, rs.getString(counter));
  62. }
  63. counter++;
  64. }
  65. rs.close();
  66. }
  67. catch (Exception e)
  68. {
  69. e.printStackTrace();
  70. }
  71. return data;
  72. }
  73. public void createMap(ArrayList data){
  74.  
  75. }
  76. public static int countLines(String filename) throws IOException {
  77. InputStream is = new BufferedInputStream(new FileInputStream(filename));
  78. try {
  79. byte[] c = new byte[1024];
  80. int count = 0;
  81. int readChars = 0;
  82. boolean empty = true;
  83. while ((readChars = is.read(c)) != -1) {
  84. empty = false;
  85. for (int i = 0; i < readChars; ++i) {
  86. if (c[i] == '\n') {
  87. ++count;
  88. }
  89. }
  90. }
  91. return (count == 0 && !empty) ? 1 : count;
  92. } finally {
  93. is.close();
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement