Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Connecting with multiple Databases, getting Data and writing data to a new database

So, i guess this should be really easy, but i started with Java just a week ago and have to finish a little team project this semester.

I already have a program that creates databases, tables and adds data into it. That wasn't to hard since there are lots of tutorials on this topic.

Now i have to write a program that is able to connect with my databases, get their data and merge it into a new larger database containing all the data from the other DBs.
And i just can't find any help on that since 3 days...

Someone told me the easiest way to to it, would be to get one Database into Java and copy the data to the second database and he wrote down a bit of code for me:
Code
package Databse;
import java.sql.*;
import java.util.HashMap;
import java.util.Vector;
import java.util.Map;

/**
*
* @autho
*/
public class Join
{
  public static void main( String args[] )
  {
    Connection c;
    Statement stmt;
    try
    {
      Class.forName("org.sqlite.JDBC");
      c = DriverManager.getConnection("jdbc:sqlite:test.db");
      c.setAutoCommit(false);
      System.out.println("Opened database successfully");

      stmt = c.createStatement();

    Vector<HashMap<String, String>> alleDaten = new Vector<HashMap<String, String>>();

      try (ResultSet rs = stmt.executeQuery( "SELECT * FROM FILE;" ))
      {
      while ( rs.next() )
      {
            int id = rs.getInt("id");
            String  name = rs.getString("name");
            String extension = rs.getString("extension");
            String  path  = rs.getString("path");
            String timeStamp = rs.getString("timeStamp");

            HashMap<String, String> datensatz = new HashMap<String, String>();
            datensatz.put("name", name);
            datensatz.put("extension", extension);
            datensatz.put("path", path );
            datensatz.put("timestamp", timeStamp);                
        alleDaten.add(datensatz);            

      }
      }  
      stmt.close();
      c.close();

    }
    catch ( ClassNotFoundException | SQLException e )
    {
      System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      System.exit(0);
    }
    System.out.println("Operation done successfully");
  }

He told me i that i have to iterate through the vector now.
Something like "for(int i=0;i < alleDaten.length; i++) doInsert(alleDaten[i]);"
and that i have to write a function "doInsert" aswell...

I just dont know how i to do this and where to start.
I don't even know what i should search for in google to get this done...
So could anyone help me with that?🤮[/code]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by john ronaldsadJul 20, 2022 06:49 PM 4 234 Jul 20, 2022 06:49 PM
Last Post: john ronaldsad
[C#] by adenfrJan 28, 2019 04:02 PM 9 266 Jan 28, 2019 04:02 PM
Last Post: itcorp
[.NET] by zetzaNov 9, 2017 12:45 PM 5 132 Nov 9, 2017 12:45 PM
Last Post: 0xDEAD10CC