Accessing Java DB outside NetBeans - java

I developed an application with a java db database .I cannot access the database records when I close the netbeans IDE with the message "Error connecting to server Localhost on port..." My connection code to the Database is :
String host="jdbc:derby://localhost:1527/Employee;create=true";
String user="admin";
String pass="admin";
con=DriverManager.getConnection(host,user,pass);
How do I fix the problem?

Netbeans automatically starts the Derby server; you can see that in the "Services" tab (Ctrl-5).
You'll have to start the database server by hand if you don't use Netbeans; see the doc.

Presumably your Derby database is hosted in NetBeans? You'll need to create a standalone database.

You would have to probably start your database before connecting (you are using server mode). Have a look into Vogella tutorial on Derby db connection from java application: http://www.vogella.de/articles/ApacheDerby/article.html

I guess NetBeans has an embedded DB instance.
Try to use
jdbc:derby:/MyFolder/MyDatabase/Employee;create=true
or
jdbc:derby:C:\MyFolder\MyDatabase\Employee;create=true
if you do not need to access the DB from multiple applications.

You can use JavaDB (aka Derby) either by connecting to a JavaDB Network Server or by using it as an embedded DB when your application opens the DB files itself.
Currently, your application is connecting to a Network Server started by NetBeans, as your URL is telling to connect to port 1527 on localhost, i.e. your system.
What you need to do is tell your application to use JavaDB as an embedded database, i.e. it should manage the database itself instead of getting Netbeans to do it instead. You can do this just be changing the URL to something like:
jdbc:derby:Employee;create=true
You may need to tweak that URL depending on where the database files are stored relative to your application's working directory.
Only one application can have the DB open at one time. So when you're doing this NetBeans won't be able to open the database, and if NetBeans has the database open your application won't be able to open it. So you may find you want to reconfigure NetBeans as a DB client.

the simplest way of dealing with these problems is creating batch files..
first of all build your java database program.. the tricky part is to start the server. the jderby is a server so it needs to be started.. that's why you start the server in netbeans. so download db derby files from "http://db.apache.org/derby/releases/release-10.8.2.2.html". after you download these files, copy your netbeans project in those db jderby files.. go and copy your database folders from where they will be saved.. and paste them in the db jderby files.. now open notepad and type
#echo
start (PATH)
start (PATH)
the first path take the path of the file named start network server.bat
the second path take the path of the jar file of your main project.
Now save your the notepad as setup.bat and run the batch file afterward.. and ur program will start the server and running your application at once...
NB: you can use a different name from setup, any of your choice but the extension bat must be available

Related

update MDB file remotely from other java web server over http

How to update an MDB file from other machines remotely over the HTTP?
I have 2 machines that are connected by the internet, on the first, I have an MDB file and on the other, I have a java web application, I want to send an SQL query from the java web application to update the MDB file on the other machine over the HTTP.
I tried to use FTP, but it is transferring the whole file b
A file such as word, or power-point or Access?
Well, a horse is a horse is a horse.
A file is a file is a file.
You don't connect to a word file to update it. You don't connect to a Excel file, or a power-point file. And you don't connect to a Access file. You OPEN a file, and THEN modify it. You can't open nor modify files over FTP, nor can you modify them over HTTP either. And you can't even do that with a plane jane text file. These are files - you have to open them to modify them. Or pull a whole copy to one side. Update that file, and then send it back.
So, you don't want to confuse the concept of a simple file, or file based system like say a text file, excel file, or Access file. These are NOT servers or say a service that you connect to. You never open a MySQL file - you connect to a server + service via tc/ip (a socket conneciton) and then send commands back and forth. You NEVER open or touch that MySQL data file. The server updates that file - not you, and not your code.
So, Access is not a server based, or socket connection based service. It is a file based system - not un-like a text file. You don't connect to a text file, you HAVE to open that file - modify it and then save it. You can't do that over http. In fact you can't even do that with FTP either. You can pull the whole file, modify and then send it back to where you got that file from.
Now, you could however setup + create some web service calls or entry points on the one site. You could send that web site some commands, and then code behind on that web site can open up that text file, word file, or in this case the Access file and make changes . But once again, just like MYSQL or say the web server? You not opening the remote file direct - are you? You are (and can) thus setup some code or web methods (even REST ones) that accept commands, and those (even sql update commands) could then be run by that remote server/service and thus update the file on that target system. In the case of Access data files?
If you look VERY close, even a ODBC connection string ALWAYS ALWAYS resolves to a valid windows path name (and a full legal qualified windows path name at that).
so, while there is a ODBC driver, the software driver still in fact uses a standard windows OS file open command against that plane jane file sitting in the hard disk. So to update that Access file, you need the driver - since it knows how to open that file, and how to update the delicate data file structures inside. So, even via ODBC? Well, it not a socket connection and you not connecting to a server on the other end - but in fact opening a simple windows file. In fact this means that you not only require DIRECT file rights to that access data file - but you actually need the windows file system!
However, sqLite is the SAME thing. There are thus some jdbc drivers. This JDBC concept is VERY similar to ODBC, but is for web based systems. You install a library on one end (where sqlite resides), and then that web service can take your sql commands (updates or query pulls), and thus the web site code now opens that local file, executes sql against it, or does a query pull , and then returns the results of your query - and the web query calls are done via that web service (rest calls) on that server. So, you can in theory shuffle commands between two web servers - and there are some types of "drivers" such as jDBC standards that in theory do wind up giving you a similar experience to ODBC.

How to access wampserver remotely

I'm trying to develop an Java Application under Netbeans IDE and I'm using Wampserver as server software. So I try to create an JDBC to access my data base remotely (under my lan) but noting happen even by changing the configuration file in wampserver according to what i found on the internet. if any one have an idea how we do that please help.

Export MySQL Server database to file

I have recently put all my java EE projects into my google drive so i can access them on my laptop and desktop computer. Some of my projects have a database component which I have the database stored in a MySQL server. Is there a way that I can export this database and just access it from like a database file which I can store in my project file so I can use it on both my laptop and desktop computer?
This is really what I would like:
-Be able to work on my java EE projects that have a database on both my computers
-Store my MySQL Server databases in a file which can go in my project folder then use java to access that database instead of going through the server
Any alternate ways of doing this would help me out this is just one way I can think of doing.
Note: I am using my laptop on the go so my desktop computer wont always be accessible from my laptop neither will I have an active internet connection always.
Thanks
Install MySQL on your laptop, then transfer database using backup/restore, e.g. using mysqldump. See https://dev.mysql.com/doc/refman/5.0/en/backup-and-recovery.html

Java application that can run entirely from a DVD

I have to create a java application that can run entirely from a DVD. The application must connect with a database that will be also on the DVD. I was thinking to use an embedded database but i dont know much about them. Do i have to start the database server from my java application and if i do, how should i do it?
Thanks in advance.
Nick Tsilivis
You can use SQLite which is a very light weighted version of SQL. It stores its data in a single file. You even don't have to log in with an username and password. Just add this jar sqlite-jdbc to your projects build path. You cann access it by following:
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:your_database.db"); //"your_database.db" is the SQLite database file on your DVD.
/*manipulate your db by using PreparedStatement, ResultSet, ...
You must have installed SQLite on your system SQLite Download
That sounds like a job for SQLite. It runs completely in your own process, so there is no need to start an external database server.

Deploy Java Desktop Application with MS Access DB

This is the first time I am going to deploy the Java Desktop Application with MS Access DB and discovered JAR package is not getting database access other then my development PC though I had the MS access DB in the same directory of the JAR file I have copied after Build the application. And I understand that I cannot connect MS access DB I created with ODBC connection of my PC. Now my question is
How can I deploy Java Desktop Application with MS access BD which will run in any computer where manual ODBC connection to the MS ACCESS DB for every computer will not require ?
I am not trying to connect MS access DB within a net work rather I am trying run this app where MS Access DB is already installed and my supplied DB will be with the JAR file and I want to access the DB I have provided from Java Front End Application.
Please help.
First you should get ODBC driver for Access database. Some computers may don't have it.
After you install that driver you should create ODBC Data Source on computer. I have no idea how to do it in Java, but ODBC Data Source configurations are stored in registry and you can add your Data Source.
Google "registry add odbc data source" or "Can I Create and Delete a DSN Using a Script" (second one is title of good article i found.
Probably you can access registry from java without any problems.
You can also use one of install-maker programs. Some of them have something like "Add Data Source" functionality.

Categories