Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. import javax.sound.midi.SysexMessage;
  2. import javax.xml.parsers.DocumentBuilder;
  3. import javax.xml.parsers.DocumentBuilderFactory;
  4. import javax.xml.parsers.ParserConfigurationException;
  5.  
  6. import org.w3c.dom.Document;
  7. import org.w3c.dom.Element;
  8. import org.w3c.dom.Node;
  9. import org.w3c.dom.NodeList;
  10. import org.xml.sax.SAXException;
  11. import java.io.IOException;
  12. import java.util.ArrayList;
  13. import java.sql.*;
  14.  
  15. public class AL {
  16.  
  17. static ArrayList<String> dateArrayList = new ArrayList<String>();
  18. static ArrayList<String> currencyArrayList = new ArrayList<String>();
  19. static ArrayList<String> valueArrayList = new ArrayList<String>();
  20.  
  21.  
  22.  
  23. public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
  24. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  25. DocumentBuilder builder = factory.newDocumentBuilder();
  26. Document doc = builder.parse("https://www.bsi.si/_data/tecajnice/dtecbs-l.xml");
  27. NodeList dateList = doc.getElementsByTagName("tecajnica");
  28.  
  29. for (int i = 0; i < dateList.getLength(); i++) {
  30. Node dates = dateList.item(i);
  31. Element date = (Element) dates;
  32. dateArrayList.add(date.getAttribute("datum"));
  33.  
  34. NodeList currencyValueList = dates.getChildNodes();
  35. for (int j = 0; j < currencyValueList.getLength(); j++){
  36. Node currencyValues = currencyValueList.item(j);
  37. Element currencyValue = (Element) currencyValues;
  38. currencyArrayList.add(currencyValue.getAttribute("oznaka"));
  39. valueArrayList.add(currencyValue.getTextContent());
  40. }
  41. }
  42.  
  43.  
  44. }
  45. }
  46.  
  47. public class Database {
  48.  
  49. static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  50. static final String databaseUrl = "jdbc:mysql://localhost/";
  51.  
  52. static final String username = "username";
  53. static final String password = "password";
  54.  
  55. Connection conn = null;
  56. Statement stmt = null;
  57.  
  58. public Database() { }
  59.  
  60.  
  61. public int insertIntoDatabase(String table, String columns, string values) throws SQLException
  62. {
  63. String sqlInsert = "INSERT INTO " + table + " (" + columns + ") VALUES (" + values + ")";
  64. Connection conn = DriverManager.getConnection(databaseUrl, username, password);
  65. PreparedStatement pst = conn.prepareStatement(sqlInsert);
  66. int toReturn = 0;
  67. try {
  68. toReturn = pst.executeUpdate();
  69. }
  70. catch(Exception e){
  71. e.printStackTrace();
  72. pst.close();
  73. conn.close();
  74. return toReturn;
  75. }
  76. pst.close();
  77. conn.close();
  78. return toReturn;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement