I have collected a source code of a java project from internet where there is a file with .sql extension. I am new to java and don,t know how to work with and get access to .sql file. How can I import the file in Netbeans and how to get access to that database. For your kind information, The project is on inventory management system and I have to get access to that database with a username and password contained inside it. What will I do now? Do I have to install any additional software or something else?
Please give a step by step procedure to do that. Thanks in advance
Doing some simple google searches I found this:
Running a .sql script using MySQL with JDBC
You could do it the way the OP did it, however its not as efficient as the answer. If you close the connection on how the OP did it in that post, and instead of writing the SQL, you can use a filereader to read from the SQL file and then use that data in the execute statement.
The only problem with his method though is that you need to install a JDBC driver.
install a kind of database(such as MySql)
(optional) install a gui tool for your database(such as navicat)
use the .sql files to create tables
install a JDBC driver, which establishes a bridge between your Java code and database
then you can access the database by using JDBC api
Related
anyone know about "BroadLeaf", can you help me?
I am using "Broadleaf" framework and convert database from hsql to sql, but I don't how to export database from hsql?
please help me?
You would need to get an external database utility that can connect to an HSQL DB and export the tables you need as SQL Inserts. Once you have the export, you can use native mysql tools to import.
I would recommend DBeaver (https://dbeaver.io/) as the database tool. This article has instructions to export data using DBeaver (https://www.techrepublic.com/blog/linux-and-open-source/two-features-of-dbeaver-that-every-database-manager-should-know/).
I will point out that exporting & importing is only necessary if you have made changes that you would like to keep. If you are using the default demo data, then that data will be loaded into whatever database is being used when the app is started.
My definition of portable is:
When I export my JAVA program to a jar file, others(who use my jar) don't need to install anything except JRE; that is, a portable JAVA SQL package is a jar file and users can use it like a normal package and don't need to install anything else.
Is SQLite for JAVA "portable"? If not, any SQL package is "portable"?
Or there is no such SQL package and users must install some SQL environment?
===========
I think I need a jar file(just a jar package!don't need anything installment!) that accepts SQL statements like creating tables.
My java program is so small so I don't want to install a big big big SQL environment like MySQL.
Just need some basic functions of SQL, like creating tables and querying.
There are some embeded database that can be implemented in the memory.The popular there are :
HSQL,H2 and Derby. (all are similar with mysql)
You can write the "create table.." to build the schema in a sql file, and the app load it and create the database. Of course, you also have to add the sql driver in advance.
But after the app finishes, the data cannot be maintained.
So, i've just finished a small java application, with database and stuff...
I used Netbeans and Mysql, now i want to export my project so i can use it anywhere i want;
any computer, even with no Mysql or Java installed!
So, i've tried some programs like Launch4j or something... but the main problem is, even if i make the .exe file, what's gonna happen with the database? it's located in my PC, so if somebody try to use my application, he can't access to the database, so the application won't work...
In other words...What is the solution that i can use to like "Combine" the database with the application, if it is possible? or create the .exe file with the database...
I hope that my problem is clear, and thank you for your answers :)
You can look at MySQL Connector/MXJ to embed your mysql database in your application.
But be aware that this package is no longer under active development:
Due to very low demand, MySQL
has stopped development and support for Connector/MXJ. Source and
binaries for previously released versions will continue to be
available from archives.
An alternative solutation would be using another database like SQLite, H2 or HSQLDB
You can create an executable jar by exporting your project through eclipse. You can do this by following these steps:
Right click on the Project
Export as Jar file
When you were programming in netbeans did you include the database within netbeans? Here is a guide on how to do this.
https://netbeans.org/kb/docs/ide/mysql.html
Also here is a second guide on how to Packaging and Distributing Java Desktop Applications
https://netbeans.org/kb/docs/java/javase-deploy.html
I hope these help.
If not just go over your step you took to build the app.
if you really want to give your users a good experience, I would suggest you implement a embedded database in your application instead.
Look at: http://www.h2database.com/
It's free and open source and I use it heavily myself.
It supports embedded (where it creates flat database files on the computer), in-memory, and server-mode, where you have the possibility of letting multiple-applications share the same database.
It's just a jar file you include in your application, and then the users wont have to install neither MySQL, have access to MySQL on a network drive or need other database software installed.
(depending on your requirements, it might also be a good idea to look into Hibernate, to have some more abstraction between the different RDBMS).
In order to get a database built-in to the application, consider HSQLDB, which is an in-memory database.
http://hsqldb.org/
It can run entirely in the JVM without any external resources.
I'm working on a program and I was wondering how to proceed since I don't want the person
that is going to use it to install any driver or make the odbc step to make the database
functional.
Thanks.
Use HSQLDB, you just need to include the jar in your classpath and you are good to go.
HSQLDB documentation
SQLite saves the database in a compact file format. It's just a library for your program that accesses the database in the file, and requires no setup or installation.
I have prepared an application that is a small demo of Student information manipulation. I have stored information related to students in a MySQL DB. Now my application is working 100% on my computer. But I want that work everywhere without depending on Database! I mean I just want "WHEREVER MY .JAR FILE GOES, DATABASE SHOULD ALSO GO ALONG WITH THAT INSIDE .JAR FILE "
So anyone who is using my application or trying it, they can realize exact result of this application.
How can I make this possible? Please someone help me.
You will probably need to look at something like HyperSQL, which is a in-memory database (which you will need to populate at application start-up). Or have a look at SQLite, which is an embedded databsase, which you can distribute as a resource in your jar.
This doesn't work. MySQL is a full-blown RDBMS. You would have to install it on every computer if you want application to use it locally. An alternative would be using SQLite.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
SQLite and Java
SQLite seems to be a good fit for your requirements.