Hi to all

I need some help to write a java program to parse 2 text file one containing the details of the database and the other the data that will be used to insert in the tables of the database

A sample for the first file :

schema : Test
Table : user(id#int;name#string;mail#string)
Table : students(id#int;name#string;class#string)

second file :

user
1;peter;peter@mail.com
2;micheal;micheal@email.com
3;george;george@yahoo.fr
students
1;jhon;CMP1
2;piere;CMP3
3;sabrina;CM4

thanks

Search for code examples on how to read files (Scanner, BufferedReader). Write some test classes that just print the data of the files
Search for code examples on how to run queries. Write some test classes that execute simple.
Use the above to read the data, construct the queries and execute them

hi, i need ony some helps ???
ok i will explain what i have done

i already rote a class that can read a texte file using readline
and one other that can create database , tables.

but i have problems in how can join all together

What you have read from one file, store it in variables and use those to create the query.

Then read the other file with the data and for each line, generate the query with the values, and pass it as parameter to a method that executes it

What you have read from one file, store it in variables and use those to create the query.

Then read the other file with the data and for each line, generate the query with the values, and pass it as parameter to a method that executes it

Sorry for the double post. Internet connection problems

hi, i need ony some helps ???
ok i will explain what i have done

i already rote a class that can read a texte file using readline
and one other that can create database , tables.

but i have problems in how can join all together

That was my request, provide your code.
We do not need verbal explanation of what is your issue in hypothetical code, we need real code and description of problem with it

That was my request, provide your code.
We do not need verbal explanation of what is your issue in hypothetical code, we need real code and description of problem with it

ok your right and i'm so sorry, this is my first post

here the source

the first one is LireFichier it can read thefile "CheminFichier"

import java.io.*;

import dbPKG.*;
class LireFichier 
{

    public LireFichier(String CheminFichier)
    {
        try{

            FileInputStream fstream = new FileInputStream(CheminFichier);

            DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;

            while ((strLine = br.readLine()) != null)   {


                System.out.println (strLine);

            }

            in.close();

            }catch (Exception e){
              System.err.println("Error: " + e.getMessage());
            }
    }

the second one is CreateDataBase

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateDataBase  wich create the database "nomBase"
{
    public  CreateDataBase(String nomBase)
    {

    Connection connection = null;
    Statement statement = null;
    try {
      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
      String url = "jdbc:mysql://localhost/mysql";
      connection = DriverManager.getConnection(url, "root", "");

      statement = connection.createStatement();
      String reqSql = "CREATE DATABASE "+ nomBase;
      statement.executeUpdate(reqSql);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (statement != null) {
        try {
          statement.close();
        } catch (SQLException e) {
        } // nothing we can do
      }
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
        } // nothing we can do
      }
    }
  }

}

and the last one is CreateTable that create table on the database "nomBase"

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateTable 
{
    public  CreateTable(String nomBase )
    {

    Connection connection = null;
    Statement statement = null;
    try {
      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
      String url = "jdbc:mysql://localhost/mysql";
      connection = DriverManager.getConnection(url, "root", "");

      statement = connection.createStatement();
      String reqSql   = "create table "+nomBase+".COFFEES " +
      "(COF_NAME VARCHAR(32), " +
      "SUP_ID INTEGER, " +
      "PRICE FLOAT, " +
      "SALES INTEGER, " +
      "TOTAL INTEGER)";

      statement.executeUpdate(reqSql);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (statement != null) {
        try {
          statement.close();
        } catch (SQLException e) {
        } // nothing we can do
      }
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException e) {
        } // nothing we can do
      }
    }
  }

}

My probleme is
can I use arrylist to store the values from the text file and then execute the two other classes
or is there a best way to join all this peaces to do the necessary

i hope i was clear

who could kindly check the code for me?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.