Skip to main content
deleted 603 characters in body; edited tags; edited title
Source Link
200_success
  • 145.7k
  • 22
  • 192
  • 481

Does this code follow standard conventions? Storing .h files in SQLite using SQLJet

Edit Swap GetDirectoryContent

Database db = new Database("test.db");
Fileaccess fa = new Fileaccess();
ArrayList<String> al = new ArrayList<String>();
try {
    db.createDatabase();
    db.openDatabaseConnection();
    fa.findDirectoryContent("C:\\test");
    al = fa.getDirectoryContent();
    for (String s : al) {
        db.insertRecord(s);
    }
} catch (SqlJetException e) {
    e.printStackTrace();
} finally {
    try {
        db.closeDatabaseConnection();
    } catch (SqlJetException e2) {
        e2.printStackTrace();
    }
}

Does this code follow standard conventions?

Edit Swap GetDirectoryContent

Database db = new Database("test.db");
Fileaccess fa = new Fileaccess();
ArrayList<String> al = new ArrayList<String>();
try {
    db.createDatabase();
    db.openDatabaseConnection();
    fa.findDirectoryContent("C:\\test");
    al = fa.getDirectoryContent();
    for (String s : al) {
        db.insertRecord(s);
    }
} catch (SqlJetException e) {
    e.printStackTrace();
} finally {
    try {
        db.closeDatabaseConnection();
    } catch (SqlJetException e2) {
        e2.printStackTrace();
    }
}

Storing .h files in SQLite using SQLJet

Improved grammer and formatting. Added a few helpful tags as well
Source Link

Is that smelly Does this code follow standard conventions?

I’m trying to get the most knowledge bylearn as much as I can on my own, with by reading lots of examples, documentations, and asking here. I would like to improve my style, to avoid smelly code and write efficient code and adhere to Java standards. I have here a

In this small partsample of code and I would like to know if its okay in view of the throw exception, open and close database connection or if its crap and I could improveget feedback on a lot. I have 2few things:

  • Exception throwing
  • Opening/closing database connection
  • Any other comments in general style

There are two classes, Database and Main. The

My Database class looks like:

In my Main class I callCall in main:

I’m really interesting in writing clean and efficient code it would be great if someone has further information for me, how I could improve this.

Is that smelly code?

I’m trying to get the most knowledge by my own, with reading lots of examples, documentations and asking here. I would like to improve my style, to avoid smelly code and write efficient. I have here a small part of code and I would like to know if its okay in view of the throw exception, open and close database connection or if its crap and I could improve a lot. I have 2 classes Database and Main. The Database class looks like:

In my Main class I call

I’m really interesting in writing clean and efficient code it would be great if someone has further information for me, how I could improve this.

Does this code follow standard conventions?

I’m trying to learn as much as I can on my own by reading lots of examples, documentations, and asking here. I would like to improve my style to write efficient code and adhere to Java standards.

In this small sample of code I would like to get feedback on a few things:

  • Exception throwing
  • Opening/closing database connection
  • Any other comments in general style

There are two classes, Database and Main.

My Database class:

Call in main:

Tweeted twitter.com/#!/StackCodeReview/status/230712386242375680
Post Migrated Here from stackoverflow.com (revisions)
Source Link
hofmeister
  • 509
  • 1
  • 5
  • 13

Is that smelly code?

I’m trying to get the most knowledge by my own, with reading lots of examples, documentations and asking here. I would like to improve my style, to avoid smelly code and write efficient. I have here a small part of code and I would like to know if its okay in view of the throw exception, open and close database connection or if its crap and I could improve a lot. I have 2 classes Database and Main. The Database class looks like:

public class Database {

    private String dbName = "";
    private SqlJetDb db = null;

    public Database(String dbName) {
        this.dbName = dbName;
    }

    public void CreateDatabase() throws SqlJetException {...}

    public void OpenDatabaseConnection() throws SqlJetException {...}

    public void CloseDatabaseConnection() throws SqlJetException {...}

    private void InsertRecord(String file) throws SqlJetException {...}

    public void GetDirectoryContent(String dir) {
        File directory = new File(dir);
        if (directory.isDirectory()) {
            String[] content = directory.list();
            for (String s : content) {
                GetDirectoryContent(dir + "\\" + s);
            }
        } else {
            String file = directory.toString();
            String extension = file.substring(file.lastIndexOf("."));
            if (extension.equals(".h")) {
                try {
                    InsertRecord(file);
                } catch (SqlJetException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

In my Main class I call

Database db = new Database("test.db");
    try {
        db.CreateDatabase();
        db.OpenDatabaseConnection();
        db.GetDirectoryContent("C:\\test");         
    } catch (SqlJetException e) {
        e.printStackTrace();
    } finally {
        try {
            db.CloseDatabaseConnection();
        } catch (SqlJetException e) {
            e.printStackTrace();
        }           
    }
}

I’m really interesting in writing clean and efficient code it would be great if someone has further information for me, how I could improve this.

Edit Swap GetDirectoryContent

Database db = new Database("test.db");
Fileaccess fa = new Fileaccess();
ArrayList<String> al = new ArrayList<String>();
try {
    db.createDatabase();
    db.openDatabaseConnection();
    fa.findDirectoryContent("C:\\test");
    al = fa.getDirectoryContent();
    for (String s : al) {
        db.insertRecord(s);
    }
} catch (SqlJetException e) {
    e.printStackTrace();
} finally {
    try {
        db.closeDatabaseConnection();
    } catch (SqlJetException e2) {
        e2.printStackTrace();
    }
}