I was wondering if I could get some advise/suggestions if anyone has experience with the following situation.
So I want to develop a java web app that "talks" with a database that is already built out in .NET. I have experience coding java web apps in eclipse that talked to MySQL DBs so I don't think the database language is that concerning.
What methods would you go about to implement this? Are there certain programs that are more useful than others? What frameworks should I use? Also, examples that I found on the web seem so dated style wise, are there things I can do to web apps coded in eclipse to give it some pop?
Thank you in advance
Microsoft has a JDBC driver for MSSQL.
Refer to: http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx
Call me JDBC on any database.
In these days, from the point of database vendor, they will give us a nice library (driver) to communicate their product from any (widely using) programming language.
Java is a big dealing programming language in world wide, so don't worry about database connection as this can be done by a jar featuring JDBC.
So your challenge is JDBC driver to suite and map to required database brand and its version.
You just need to worry to be right plug between the database's version and the JDBC driver library (jar file) version. Don't care on any database of MySQL, Oracle, MSSql or so on.
Java app -> JDBC Driver -> Database
Famous database's JDBC drivers;
MSSql JDBC Driver (What you need one?)
MySql JDBC Driver
Oracle JDBC Driver
Related
Are there any other means of connecting java applications to DB other than JDBC? Like when we use Hibernate in our java apps, i believe Hibernate internally used JDBC mechanism to eventually connect to DB.
So my question is that is JDBC the way in which we connect to DB?
Thanks
In general, JDBC is practically always used to connect to SQL databases, either directy or under the hood by an ORM. NoSQL-Databases use other APIs.
In my opinion, JDBC would be the first choice so really would not be seeking alternatives. That said, one could use the JDBC-ODBC bridge. Your app is still written to JDBC but the connection to the DB is with an ODBC driver. I would much prefer the fully Java approach of a JDBC driver. Depending on what database you want to access, they may have Java libraries that expose their native API and you could write to that. Bur, your code would be completely non portable to other database if you ever wanted to expand. A well written JDBC app should be able to access different databases simply by plugging in another JDBC driver and adding the appropriate connection information. Also, if you needed an assistance later on with JDBC being fairly widely used it will be easier to get than assistance than with a native solution.
I am left wondering why you're searching for alternatives to JDBC though.
JDBC is a standard all ORM tools need to follow while connecting to DB using Java
i was wondering, why does it have to be so complex to develop a swing application that works with a DBMS on java?
I would expect it to be as simple as it is to develop an android app with DBMS, which is pretty much straight forward with the android.database.sqlite package...
Specifically, i would like to know why would it make you connect to the DBMS with URL's and have to install so many background complicated things just to get it to start working?
and do you guys know of a java package that works similiar to the android package for DBMS? or is there a way to include this package and work with it in a regular java project?
I think you question is too generic.
You can use SQLite in Java SE/Java EE in various ways.
For example - have you taken a look here?
You should understand that the standard way to access relational DB is via JDBC.
Jdbc provides you an abstraction API for database access, and since it supports many DB vendors,
It has for example to support loading the property JDBC driver, which provides a vendor-specific implementation for the DB vendor in use (for example - mysql and oracle DB have different JDBC drivers).
As far as I know, this is not the case with Android - which currently has a single "DB provider" - SQLite, so in case of Android development you can skip the "Vendor driver loading" as you have one vendor.
However, there are various frameworks that allow you to simplify the work with relational database, such as spring-jdbc.
Your java program is possibly going to run on a windows, linux, apple (or other) box. It has the ability to connect to mysql, postgresql, sql server, oracle or sqllite. It needs to be able to connect under all those operating systems potentially to all those databases. This flexibility comes at a cost.
Your android app is going to run on the android os with the sqllite database. This can be baked into the os, making life easy for you. But that app won't run on iOS or WinPhone.
I've used JDBC in several applications now to query Derby, PostgreSQL and now MySQL databases. I guess I'm choking on some basic terminology in my attempt to understand what is actually going on underneath the hood. Several terms I've seen batted around:
ODBC
JDBC Driver
Bridge
JDBC-ODBC Bridge
For each of those I did my best to do some digging and gain an understanding of what they are, what they do, and how they relate to one another. I believe I'm about 70% of the way there, I just can't seem to find anything (articesl, blogs, docs, etc.) that tie everything together nicely and confirm my suspicions.
It seems that ODBC is a C library (perhaps a DLL?) that programs can use to communicate with RDBM systems (such as PostgreSQL and MySQL). All queries to these systems flow in and out of this library on a given system.
The JDBC-ODBC bridge is a Java component that contains native code that allows JDBC to communicate with that ODBC library on a given system.
JDBC is a pure Java API for querying RDBM systems.
A JDBC driver (such as a PostgreSQL-JDBC Driver) is where I'm really having trouble. If all RDBM systems follow RDBMS standards, and can communicate with the ODBC library, then why does JDBC need different "drivers" for each of them?
What are these drivers? What do they do? Why are they necessary? Also clarification on any other assertions I've made here would be enormously appreciated. Thanks in advance!
You are almost there. Good question.
What are these drivers: A pure JDBC driver is a driver written in Java, that does not need an ODBC driver to work. You should only use ODBC drivers (through JDBC-ODBC bridge) when you don't have a direct JDBC driver for your database (which is extremely rare, since most {if not all} databases support JDBC nowadays).
A pure JDBC has the advantage of not needing ODBC. ODBC is usually hard to configure, and requires a database native client library to be installed on the system (such as Oracle OCI, or Sybase CT Library).
It used to be the case that ODBC or native drivers were chosen for performance reasons, but I think today pure Java/JDBC perform almost as good as their native/ODBC counterparts.
What do they do: the same as ODBC. A standardized Java API to access relational databases.
Why are they necessary: They are necessary because it simpler to work with them, you just need the JDBC library JAR and your URL connection. Opposed to: native client library + ODBC driver + JDBC-ODBC configuration. It's also the case that every single database has its own network protocol to perform queries against it, and to get results back. So you need one driver for each database vendor. Each one of them implements the specific protocol it needs to connect to its relational database manager. If you were on a world where all database shared the same SQL language and the same communication protocol, you would only need one driver. But that won't happen any time soon.
ODBC and JDBC are equivalent. They both use drivers to transform ODBC (or JDBC) calls into the native database commands. ODBC is older and written in C/C++, while JDBC is written in Java. When JDBC came out, there were no JDBC drivers for most DBs, so they created the JDBC-ODBC driver to allow people to utilize the already available ODBC drivers. This is rarely used now, since almost every DB has a pure Java JDBC driver
Just because DBs use "standard" SQL (and that's in quotes for a reason), does not mean that the DB use the same lower level protocol for communication. SQL is simply a syntax, but not a protocol.
The protocols for Postgres and, say, Oracle are wildly different and offer different features, even though they both use similar SQL features.
SQL itself, while standard, has wide deviations in implementations. MySQL for example is notorious for being less SQL compliant than other DBs. While much SQL used today is portable across DBs, there is much that is not.
JDBC and ODBC are kindred spirits. They provide a shared interface that your application can use to talk to an RDBS. They also provided a common model for vendors to implement. These are the drivers.
Vendors implement a driver to allow a JDBC/ODBC compliant program talk to their database. The drivers task is convert ODBC/JDBC calls in to the appropriate SQL or and other control calls for the database.
The JDBC/ODBC Bridge is a JDBC driver that talks to an existing ODBC driver. It's an abomination. Don't use it. Every database of note today has JDBC drivers. And stick with "type 4" JDBC drivers if at all possible, since these are native Java rather than "type 2" drivers that use JNI to a binary. Buggy type 4 drivers give exceptions, buggy type 2 drivers give JVM crashes which nuke your appserver. No thanks.
You're right; you're very close to having the full picture!
JDBC and ODBC are conceptually very similar. They're both frameworks for interacting with databases. JDBC is Java-specific, while ODBC is Windows-specific. That said, both JDBC and ODBC are actually toothless APIs. In Java terminology, JDBC is actually a set of unimplemented interfaces. While they specify a behavioral contract, they don't inherently know how to talk to any specific database. That's where drivers come in.
Let's talk specifically about JDBC here. JDBC drivers are concrete implementations of the JDBC interfaces that actually know how to talk to an underlying database engine. JDBC guarantees that a ResultSet from the MySQL JDBC driver will behave the same way as a ResultSet from the Postgres JDBC driver.
As others have pointed out, a JDBC/ODBC bridge is just a bit of glue to make code written for JDBC to work with ODBC infrastructure. Generally, that only makes sense if you know with certainty you're writing Java for Windows exclusively; ODBC is Windows-specific, but JDBC is (in theory) cross-platform.
Jdbc is the java way to connect to a database using dricers written in java (since JDBC4).
ODBC is the MS Windows way to connect to a database, these drivers are usually written in C
A JDBC-ODBC Bridge is something rather old, in early days of java there were not all drivers in a JDBC version available, so the build a generic bridge beteween JDBC and already existing ODBC drivers.
I have been asked to learn JDBC. I do not know where to start. I have started with some books. It's using some SQL tables (I am also new to SQL). So I want any of you to assist me that the topics that should be covered for JDBC. I also want to know how to creae a simple DB in Windows, so that database will be connected to my program.
Which books, materials are useful to know for:
Java Beginners
JDBC
Connection between Java & JDBC (I do not know whether its right or not)
Relation between Java & SQL.
Java Beginners
Head to Sun Oracle's own tutorials.
The Java Tutorials - Getting started
The Java Tutorials - Learning the Java language
The Java Tutorials - Essential Classes
The Java Tutorials - Collections
JDBC
Again, the vendor's own tutorials are the best (only learn it after basic Java!):
The Java Tutorials - JDBC basics
You'd like to learn SQL first beforehand (learn it before JDBC):
W3Schools - SQL tutorial
Connection between Java & JDBC (I do not know whether its right or not)
JDBC is a Java API (a set of interfaces and classes). There is no such thing as "connect between Java and JDBC". You rather want to connect between Java and the database. You use JDBC for this. You first need to know the JDBC URL of the database in question and the login username and password. Then you can connect it like follows:
Connection connection = DriverManager.getConnection(url, username, password);
How the URL should look like depends on the DB and JDBC driver in question. You'd like to consult the documentation of the JDBC driver in question.
Relation between Java & SQL.
Nothing. Both are separate and independent languages each with an own purpose. SQL is a database communication language. Java is an object oriented programming language. In Java, you can use the JDBC API to execute SQL programmatically, but that's also really all.
I also want to know how to creae a simple DB in Windows, so that database will be connected to my program
Just choose a database server and download and install it. There are several popular choices:
MySQL - JDBC driver
PostgreSQL - JDBC driver
Oracle - JDBC driver
MS SQL Server - JDBC driver (jTDS JDBC driver is better)
IBM DB2 - (no public JDBC driver, it's included in DB2 install folder)
Each of them also ships with DB vendor specific JDBC documentation. It's also worth to get yourself through it (only if you already understand basic JDBC!).
See also:
JDBC tutorial with MySQL
DAO tutorial with MySQL
Start by focusing on accessing a Database using SQL.
JDBC just lets your write Java code to call the SQL, so you need to understand SQL first, and to understand SQL you need to understand Databases a little: Tables, Columns, Keys.
So you could work through a tutorial such as this link text.
I have thought of creating my first database application for one of my projects using Oracle and Java. I have chosen Netbeans as my development environment. I have a few questions to getting started.
This will be a data intensive (yet still for a college project) database application. I do not need 1000 user concurrency or any other very advanced features but basic stuff such as triggers, stored procedures etc. Will the 11g "Express" (XE) suffice for my requirements?
Do i need any Java to Oracle bridge (database connectivity driver eg. ODBC etc) for Netbeans to connect to the oracle database? If yes, what are they? Does Netbeans support Oracle databases natively?
Any easy to follow guide on how do I connect to the database and insert/retrieve/display data on a J2SE application? (I know that i should Google this but if there's any guide previously followed by anyone and is considered easy, it would be greatly appreciated.)
There are several different ways to access databases using Java. I'm assuming you are wanting to use JDBC, which is included in all recent JDK's. There are other layers on top of JDBC like Hibernate that may make things cleaner for larger applications, but may also be too steep a learning curve if you have a project to complete and submit.
To answer your questions in order:
I think it's highly likely that Oracle 10g Express Edition will do what you need for a college project. It's pretty much the 10g Standard Edition with a 4GB limit on data size.
You will need a JDBC driver to access the database from Java. It comes with XE, and is installed in <XE client install dir>/jdbc/lib/ojdbc14.jar
Sun have an introduction to JDBC here.