I would like to know how can I use php-java bridge but only to connect to database ..and then i would like to use PHP to view data from DB, to update data from DB and to delete data from DB through PHP files(interface)
What Database are you using?
If you use MySQL, SQLite or MongoDB, there is no need for a bridge since Java can connect to all of them directly. To connect to MySQL (for example) you would use JDBC.
I've done it using Zend Server Community Edition - it has a java bridge option that I am currently using.
However...I have a different opinion on how to get to your destination thast will be faster and easier. To have the ability to switch out databases or use multiple databases is easy in php - use pdo, and you'll be able to keep it generic. You can even connect to MSSQL if you wanted to - it's all there. With PDO prepared statements (your queries) you'll also have similiar security without creating an additional database layer.
Please note: If you already have Java code already written to server as a model, however, rock out!
Related
Working on a JAX-RS application which uses Microsoft-SQL-Server as a Database.
It does not use any ORM frameworks, just plain old JDBC.
Most of the application's operations involve store and retrieve data as XML into DB tables.
I have a use case where I have to run this application offline. So there wont be any connection available to DB SQL-Server.
Whilst looking into my options thought I would embed the DB and ship with the application EAR.
Looking into options I learned that, SQL-Server-Compact does not have a proper JDBC driver.
Is there any other In-Memory DB that could serve my purpose?
I want avoid any code changes like: changing the SQL queries (written specifically for Microsoft-SQL-Server).
Is there any solution which I can use and ship my application just by changing the DataSource to embedded DB?
note: I could not find any useful post on stackoverflow for this query, If it's already been discussed. Please point me to the post and I will delete this duplicate question.
I want to create a data management system which will be used via a GUI, by many users in different locations. I want to use client/server connections when a user logs into the GUI, and then whenever anything is added/updated, the database is updated accordingly. I am wondering firstly, if this architecture is logical and will work? And secondly, whether I need to store the database online, or if it can be stored locally and then accessed by people online using the GUI? The database is currently in MS Access however I can migrate to another program if it will make things easier.
I am doing the GUI in Java and will use JDBC to access the database.
There's no 'best' option, but a good solution would be to develop some web services that channel traffic to and from the database, then have your GUI call those web services.
That way you can control access far more easily, as well as ensuring data integrity by having the web service perform validation and sanity checks.
i would suggest you use mysql database your connection is something like this in java jdbc
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://remoteUri/database-name?"
+ "user=user&password=userpw");
Yes, it is possible. Firstly you have to create a database (I would recommend Oracle). Then in your GUI you can connect to the database and each button in your GUI will do certain SQL statements that will alter the data in the database.
A good website I found is : http://www.homeandlearn.co.uk/java/java_and_databases.html
I want to make java code that creates a sample database in 3-4 DBMS like mysql, oracle sql, sql server etc installed on any OS - windows, linux distro, Mac OS etc.
How can I make my code:
automatically (or with help from a user) locate the jdbc driver in the computer.
execute a fixed set of sql commands which will work regardless of the DBMS used.
Please suggest how I can do all these things.
EDIT:
This will be a back end kind of app.
I am a little new to JDBC, so I am looking for simple/elementary solutions to begin with.
Will switch to advanced ones later.
Thanks.
Bundle drivers for all the supported databases with your program. Users shouldn't have to deal with JDBC drivers or connection strings. (Provide a UI to edit the latter, which might differ between the databases.)
Use an ORM (like Hibernate); or, if you don't need to populate the database with data, a database migration library (like Flyway)
1, See here... How to use a JDBC driver from an arbitrary location
2, Different DBMSs use similar but not identical syntax. You have at least 3 options:
only use sql commands that are supported by all the DBMSs you're interested in;
sniff the DBMS and modify your SQL statements accordingly;
use a framework that comes with an SQL abstraction layer (e.g. Java Persistence API's JPQL). I suspect this may be too much work for what you're after.
If you want to let users find the JDBC drivers, then you shall deal with ClassLoaders and implementing custom ClassLoaders, which is not a simple thing to do. Or you shall use a Application Server which will handle this for your.
Otherwise you shall have all your JDBC drivers available in your class-path.
By the way JDBC is an adapter for working with most RDBMSes which work with SQL, each database provider made vendor specific customization to their SQL. For example you have sequences in Oracle and auto-numbers in MySQL. Or you can use limit in MySQL queries which is not available in Oracle. The solution to this problem is doing what Hibernate does (having Dialects for handling database vendor specific stuff.)
I have an Oracle database that runs a PL/SQl job once every week to copy data from a table in the Oracle database to another Oracle database using Oracle database links. Both systems run on Unix/Solaris. The job is scheduled and executed via the Unix Cron facility.
The remote machine is now being migrated from UNIX to a Windows platform with a MSQL Server database. I have been looking into the possibility of using Oracle database links to connect from UNIX to the MSSQL Server database which will be running on a Windows platform. It is possible but it looks to me like there is a lot of fiddling around to get it to work and there is not a lot of information on how to implement it.
The other solution i am thinking of is to implement the process as a Java daemon process that will run every week. All it will do is connect to the Oracle database read data from some tables, connect to the MSSQL Server database and run some insert commands. I think i will need two kind of drivers for this - i.e. jdbc for Oracle and jdbc for MSSQL Server.
Does Spring provide any facility that will make the above easier to implement and or maintain? (Specifically the multiple drivers and the scheduling part of the requirements)
Is Hibernate suitable for managing the multiple database connections or is that overkill?
Feel free to also suggest a better solution :)
Thanks
Spring has extensive support for scheduling tasks.
Running queries against multiple databases via different drivers is a basic JDBC feature; Spring is not really relevant there - unless you want it to happen in a single (distributed) transaction. Spring does support those via JTA and XA.
This sounds like a perfect application for Spring Batch
You should check these Pages to see what it's about:
Features
Use Cases
Spring Batch will happily accept different datasources with different drivers, but you will probably have to provide some RowMapper objects to create interim Objects.
I am creating a web application that is accessing a SQLite database in the server. I also have "clients" that updates this same database. As we know SQLite locks the entire database during INSERTs which are done by the clients and the web application is also trying to make some UPDATEs at the same time. So my problem now is about concurrency in database access. I would like to use an embeddable database like SQLite. Any suggestions.
H2 database the new thing from the creator of Hypersonic SQL: H2 stands for Hypersonic 2, however H2 does not share code with Hypersonic SQL or HSQLDB. H2 is built from scratch.
HSQLDB
If you value convenience over raw performance the database bundled with Java 6, JavaDB/Derby, may work well for you. It offers row-level locking and has it enabled by default.
You've got to the point where I would be switching to using a separate database server. The SQLite wiki has a page on when to use SQLite and when not; highly concurrent writes are one of the times when you're beyond its architecture (which deliberately doesn't handle this case well so it can do better at others).
PostgreSQL and MySQL are probably your first ports of call.
Try Oracle's Berkeley DB.
Thought about MySQL? We're using it in our application an it works great.