Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.sound.midi.SysexMessage;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.parsers.ParserConfigurationException;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import org.xml.sax.SAXException;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.sql.*;
- public class AL {
- static ArrayList<String> dateArrayList = new ArrayList<String>();
- static ArrayList<String> currencyArrayList = new ArrayList<String>();
- static ArrayList<String> valueArrayList = new ArrayList<String>();
- public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse("https://www.bsi.si/_data/tecajnice/dtecbs-l.xml");
- NodeList dateList = doc.getElementsByTagName("tecajnica");
- for (int i = 0; i < dateList.getLength(); i++) {
- Node dates = dateList.item(i);
- Element date = (Element) dates;
- dateArrayList.add(date.getAttribute("datum"));
- NodeList currencyValueList = dates.getChildNodes();
- for (int j = 0; j < currencyValueList.getLength(); j++){
- Node currencyValues = currencyValueList.item(j);
- Element currencyValue = (Element) currencyValues;
- currencyArrayList.add(currencyValue.getAttribute("oznaka"));
- valueArrayList.add(currencyValue.getTextContent());
- }
- }
- }
- }
- public class Database {
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String databaseUrl = "jdbc:mysql://localhost/";
- static final String username = "username";
- static final String password = "password";
- Connection conn = null;
- Statement stmt = null;
- public Database() { }
- public int insertIntoDatabase(String table, String columns, string values) throws SQLException
- {
- String sqlInsert = "INSERT INTO " + table + " (" + columns + ") VALUES (" + values + ")";
- Connection conn = DriverManager.getConnection(databaseUrl, username, password);
- PreparedStatement pst = conn.prepareStatement(sqlInsert);
- int toReturn = 0;
- try {
- toReturn = pst.executeUpdate();
- }
- catch(Exception e){
- e.printStackTrace();
- pst.close();
- conn.close();
- return toReturn;
- }
- pst.close();
- conn.close();
- return toReturn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement