I want to create a java application which will use Sq Lite database and after making jar file my application will read and write Sq lite database file. So how to achieve this.... please give me overview how to access Sq lite database file and modify it. after making jar file.
Asked
Active
Viewed 2,931 times
-2
-
1You should tell us more about your IDE what structure you want to store and more about the whole scenario. Is the DB already there ? Besides that there should be answers to your question that can be found by searching – Marged Jun 13 '15 at 17:18
-
1It would improve your question if you were more clear about which of these things you already know how to do. If you don't know how to do any of these things, then asking how to do all of them at once isn't a good question for StackOverflow. Search for and read some tutorials, and when you get stuck and have specific questions, you can ask each of those here. – Dan Getz Jun 13 '15 at 17:30
-
2Sir I have made a typing speed game and in order to save and load the score i use Scanner and Formatter for reading and writing the text file. So when the jar file of my program is created then it will create text file near to it. So that text file is used to save and load the score of the game. So now I want to use database to save and load the score instead of text file. So when any user play my game his score should be saved in the database and should be load from the database. – muler Jun 14 '15 at 09:22
-
2Moreover as Jar File can not be modified so database file should be placed outside the jar just like text file. And I want to use SQLite database but I do not know where to place SQLite database file so that when I make Jar file of my project, my application should access that database file and can modify it. So please guide be where i should place that database file. – muler Jun 14 '15 at 11:18
-
2@Marged i use eclipse IDE and score of the game should be stored in table format consist of 3 columns such that (1. playername playerscore) and Firstly database file should be empty it does not contain any data when user play game his score will be save and when the next time he play the game his saved score should be displayed. I myself can save and load the score through the code but I need guidance of where to put the database file so that it can be access able and modifiable by the jar file. – muler Jun 14 '15 at 11:22
-
@muler do you think it makes sense to use a database for this ? How many players do you want to support ? – Marged Jun 14 '15 at 12:59
-
1@Marged yeah database is not needed for this so that's why i used text file. but now i want to learn java database but i do not know where to start. So i want to implement database in this program for sake of learning. – muler Jun 14 '15 at 14:07
-
1I wanted to know how to modify the database record when the application is distributed it runs fine on eclipse but when jar file of the application is created then how to connect my app to that database file and modify the data. So it is good start to implement database in that program so that I can learn how database works. So after that I can use database in a complex program. – muler Jun 14 '15 at 14:16
-
@muler You know that sqlite does not have all the functionality a "full-grown" database has ? If you really want to start with a database you don't have to pay for there are alternatives. What are the prerequisites for the database you want to use ? embedded / standalone ? pure java approach needed / non-java allowed ? 100% JDBC functionality covered / less then 100% ok ? ... – Marged Jun 14 '15 at 14:24
-
@Marged so please guide me which database i should use ? my requirement is that when i develop an application which uses database should run on every computer my app will be able to modify the database. i search on the net and I get suggestion of using SQLite or HyperSQL database. – muler Jun 14 '15 at 14:46
-
@muler do you really plan to ship a _concrete_ application to someone ? Or is this just an example ? If you ship a game which stores data in a database forging gained points will be just too easy. If you are up to "I will do database today" and simply use a made-up application / game for that this is ok – Marged Jun 14 '15 at 15:13
-
@Marged no dear I am not. I just want to learn how to create database for those kind of application which may i should built in the future. so i just wanted to know which database engine i should use that satisfy my requirements as i do not have enough knowledge about databases. – muler Jun 14 '15 at 15:27
-
@Marged I will be very thankful for that if you guide me or give me a demo about making database for those kind of applications... – muler Jun 14 '15 at 15:32
-
@muler sorry, stackoverflow is not about teaching such a relatively big topic step-by-step. My suggestion is that you learn how to export a jar from Eclipse. This should be a relatively easy step which will give you your complete program in a single jar file. The next step is to learn about JDBC, you can make your first steps with sqlite (or derby, or h2, does not matter). All of this can be found by googling tutorials of the mentioned topics. When you have problems with a specific step you are always welcome on stackoverflow. – Marged Jun 14 '15 at 18:55
-
@Marged I was asking that simple solution........ – muler Jun 22 '15 at 18:41
1 Answers
4
It is very simple just place the Sqlite Database file inside your project folder and then in your program in order to connect to the database file create the connection like
connection = DriverManager.getConnection("Jdbc:sqlite:name of your sqlite database file");
Now in order to connect to the database file after creating Jar file of your program just simply place your sqlite database file near to the created Jar file... After that you will be able to communicate to your database file(can access and modify data) from your application(Jar file)... Thanxxxx...... :)

muler
- 61
- 1
- 6