Results 1 to 13 of 13
- 08-25-2010, 09:15 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
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(); } }
- 08-25-2010, 09:58 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you explain that how did you run in localhost? What it's really means?
- 08-25-2010, 10:25 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
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.
- 08-25-2010, 10:32 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Okay, that's fine and I hope you've done all the configurations properly. Database?
Did you try to debug the code?
- 08-25-2010, 12:57 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
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
- 08-25-2010, 02:34 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
How does it call this class on the server?
How is it wired up?
What framework are you using?
- 08-25-2010, 06:15 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
default constructor passing the java bean then uses data in that bean method call like so
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.Java Code:Datastore db = new Datastore(validator.getBean()); db.saveData();
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.
- 08-26-2010, 08:49 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 08-26-2010, 09:07 AM #9
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
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();
- 08-26-2010, 09:13 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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?
- 08-26-2010, 09:41 AM #11
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
Issue resolved, the connector places the database within the apache server binaries unless specified. :)
- 08-26-2010, 09:42 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 08-26-2010, 10:14 AM #13
Member
- Join Date
- Aug 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Java Dossier, Piano Student Database. Main help!?
By Peril in forum New To JavaReplies: 2Last Post: 03-09-2010, 09:42 AM -
How to convert Sqlite database table into XML file
By sahnse in forum New To JavaReplies: 1Last Post: 12-18-2009, 01:16 AM -
Running main in a package...
By Bizmark in forum New To JavaReplies: 1Last Post: 04-07-2008, 01:58 PM -
how to create java client to access web services running on https/ssl
By navneet1083 in forum NetBeansReplies: 0Last Post: 11-13-2007, 10:13 AM -
Call a main method from within a running program
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks