Results 1 to 13 of 13
  1. #1
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Post SQLite database wont create during web app running but will when run as main

    Hi,

    My title says it all, when run the below code as a main, it creates the database. When it is run on the localhost; it doesn't create the database. No runtime errors. :s Im gussing it is a configuration issue or the paths are different during runtime.

    I run tests and the data is within this class file during runtime.

    Java Code:
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws SQLException {
    
            try {
                // TODO code application logic here
                Class.forName("org.sqlite.JDBC");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
    
            Connection conn = DriverManager.getConnection("jdbc:sqlite:Contribution Log Records.db");
            Statement stat = conn.createStatement();
    
             Calendar rightNow = Calendar.getInstance();
    
            data.....
    .....Table creation
    ...Inputting data
    ...
    ..
    
            conn.setAutoCommit(false);
            prep.executeBatch();
            conn.setAutoCommit(true);
    
            ResultSet rs = stat.executeQuery("select * from Logs;");
    
            while (rs.next()) {
                System.out.println("name = " + rs.getString("name"));
                System.out.println("job = " + rs.getString("email_address"));
    
            }
            rs.close();
            conn.close();
    
        }
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    Netbeans 6.9 creates a local host on port :8080 (//localhost:8080) for the app to run on. (I believe my understanding is correct).

    My app is a request form, the dispatch servlet calls this database class and the data is taken from a java bean.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Okay, that's fine and I hope you've done all the configurations properly. Database?

    Did you try to debug the code?

  5. #5
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    Please read above no runtime or compile errors and it runs seperate from the web application when invoke within the project. I has put in basic data it is a connection error

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default

    How does it call this class on the server?
    How is it wired up?
    What framework are you using?

  7. #7
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    default constructor passing the java bean then uses data in that bean method call like so

    Java Code:
     
    Datastore db = new Datastore(validator.getBean());
    db.saveData();
    Wired up? If you mean have i done a white testing to check communication between classes then yes. Please refer to first post. Data is visible within the forum. I have made it pass data from the datastore class back to the selvet to test and it works.

    Can you clarify do you mean by framework? SQlLite, JDBC connector

    The Connection error is in reference to the fact no database was created during the runtime of the web application, runs indepently. Is a .War different to a .Jar during class calls where does it expect its' connectors to be?
    Last edited by teckygamer; 08-25-2010 at 06:36 PM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default

    What I mean is, you have a main() here and you are implying you're calling it via your Servlet.
    I'm asking how you are calling this code.
    If it isn't this code in main() you are calling then what code is it?

    As for wiring up, I wanted to make sure the Servlet that used this (and it wasn't clear how this fitted in, which is why the question above) was being called. In other words, how does this bit of code you have given at the top fit in with the call to the server that is being made?

    And, since you refer to a dispatch servlet, I wanted to see if you were using a framework like Spring or Struts which use dispatchers (or similar) to farm calls out to Controllers and Actions respectively.

  9. #9
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    Datastore and main have the same code within the clasess.

    The dispatch is dealing with the request and the form, no problems there.

    Flow of servlet validate fields, store fields i bean, use beans to send data via email then store details from bean in DB, redirect to another web page.

    Everything works fine, my query focuses on this part of the code. no database is being created, the rs.next has the databse and prints the data(Probably should have been more clear with this fact). No persistent database creation, it is as though something gets killed.

    Java Code:
         try {
                // TODO code application logic here
                Class.forName("org.sqlite.JDBC");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
    
            Connection conn = DriverManager.getConnection("jdbc:sqlite:Contribution Log Records.db");
            Statement stat = conn.createStatement();

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default

    Right.
    So this code is called and working, but sql lite isn't creating the db file?

    I'm trying to get a handle on the actual problem. It originally sounded like the whole db stuff wasn't working, but now it sounds like there simply isn't a db file being created?

  11. #11
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    Issue resolved, the connector places the database within the apache server binaries unless specified. :)

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default

    Where you had looked was going to be my next question.
    It had to be there somewhere since SQL lite wouldn't have been working.

  13. #13
    teckygamer is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    Within the project directory, it is why i asked the difference between .WAR and .JAR.

    My understanding is that it places the db within the apache server binaries because at runtime this is where the root directory while the wep app is depolyed.

Similar Threads

  1. Replies: 2
    Last Post: 03-09-2010, 09:42 AM
  2. Replies: 1
    Last Post: 12-18-2009, 01:16 AM
  3. Running main in a package...
    By Bizmark in forum New To Java
    Replies: 1
    Last Post: 04-07-2008, 01:58 PM
  4. Replies: 0
    Last Post: 11-13-2007, 10:13 AM
  5. Replies: 1
    Last Post: 08-07-2007, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •