Create and connect a database in java - database

i am using Netbeans 6.9.1 & GlassFish Server 3.
It is my first time trying programming using datatbases in Java.
I have sketched an E-R diagram for my database. I want to create a database in java, including tables and fields. Then, i want to connect my database with a server. Should i connect it with the GlassFish server? I want to submit queries and be taken results.
Could you please provide me some advice?

First, you should read up on JDBC. That is the Java language library for accessing databases. It sounds like you want the tables automatically created. I suggest you look into Hibernate or Apache Cayenne. Both of those are ORM frameworks that take a lot of the SQL out of the process and let you focus on writing Java classes.

Related

Using SQL Server for practise on Cloud

Is anyone offering SQL Server for free on cloud for learning purposes? I need it for running simple queries that we come across while learning SQL concepts online. If available I can run the queries in my mobile or tab
If you are looking for online sql , I would like to suggest you
http://sqlfiddle.com for practice purpose.It support MySQL, Oracle, MS SqlServer, Postgre, SQLlite (create your account and save your work)
http://www.w3schools.com/sql/default.asp is another great option to
run queries while learning it.
Another +1 to w3schools. They have various demo databases that you can both query AS WELL AS modify. You can restore the original database with the click of a button which is great if you are learning. I have put a screenshot of an example that I just did so you can see what it looks like.
Also, because this is web based and all of the queries are handled on the server side, you can use this from any device with internet access, including iPad/Phone whatever.
http://i.stack.imgur.com/1cxUp.png
SQLFiddle is another great option, especially because you can select specifically which language you are using (MySQL, Oracle, MSSQL, etc) but it is a bit more advanced if you are just starting out because you will have to create a database/schema and insert data instead of simply manipulating existing data like you can with w3schools.

Entity Framework with Multiple DB Engines

We have a few .Net application that we would like to start using Entity Framework 5.0 but the problem is that our customers can choose to use one of any of the following database engines:
SQL Server (95% of Customers use this engine)
Oracle (3% use this engine)
DB2 (2%)
So as you can see an overwhelming majority of our customers use SQL Server. So my question is that assuming that each database engine will have the same exact schema layout then all we should have to do is to change the entity connection string to target each of these engine types, correct?
Sorry if this seems to be a simplistic question but I just wanted to make sure that I was on the right track here.
I do not know Entity Framework, but the are many differences between the DB engines.
For example the security, in DB2 is always external (OS secutiry), in Oracle most of the time is internal. Procedure language is different, and I hope you don't use it for a multi-platform application.
The best is to try the execution with each database, and tune the procedure in order to work in all of them, but I think you have to do more that change the connection string.

(java) data entry gui builder from (oracle) db schema

Does anyone know of a tool that ingests an Oracle database schema and generates a (preferably but not exclusively Java) data entry GUI? Dabo is an example of a tool that allows you to build a GUI but it uses python and is not yet ready for Oracle (according to the website) and doesn't automatically produce a GUI.
The following tutorial at by NetBeans called Creating a Simple Database Client in JavaFX Composer could be of interest to you. As long as you can connect to your Oracle database through JDBC as a data source, this should work for you.
For web based, you have a lot of options. Django is indeed one of them. Other is cakePhP and I'm sure there would be a Ruby analog as well.
There are also technologies that go across desktop/web e.g. Adobe Air as well.

phpmyadmin and the database

Not sure I fully understand what phpmyadmin does.
I created a database in phpmyadmin, and would now like to start accessing the data in it from php. However I have no idea where the database is?
Should I export in the phpmyadmin software? I tried that but it came up with a .sql file which can be opened in notepad and contains the SQL statements used to create the datbase and the one table inside. Basically that doesn't look like a database to me.
phpMyAdmin is just an interface to work with an existing MySQL database server. However you have configured phpMyAdmin to access the MySQL database is the same information you need to access it through PHP. You will need the server name/ip, username and password.
There are many tutorials available online that can help you get started.
phpMyAdmin is an application, written in PHP, to provide a convenient interface to your MySQL database in the browser. It's not needed in anyway to connect to the database server from PHP. To do the latter, you'd typically find the right function names from the PHP documentation and get some examples. Start here, for example: http://www.php.net/manual/en/book.mysql.php (and investigate mysql vs. mysqli vs mysqlnd options).
Your MySQL server will usually run on localhost:3306, but you have probably entered those details while setting up the phpMyAdmin install, anyway.
PHPMyAdmin is only a graphical front-end to the mySQL database.
PHP has built-in functions to access a mySQL database, those are totally separate from phpMyAdmin.
For reference, here is the PDO documentation which is one of several methods to access PHP, and definitely one of the more recommendable ones.
It is recommendable over mySQL because it supports parametrized queries by default, the lack of which made many PHP applications based on the standard mysql_* family of functions vulnerable to SQL injections. That is not to say that it's not possible to program safe scripts with the mysql_ functions, but PDO makes it easier.
The docs are a bit tough to get started with the subject, though. I'd wait, I'm sure someone will link to some good english-language tutorials.
The MySQL server runs on a known port on a given server (EG: localhost), with a given database (EG, it might be called: "myDatabase"). You should be able to configure phpMyAdmin to point to that server, host, and database.
You have to write your own php code to interact with mysql.
phpMyAdmin is a tool to interact with mysql independantly of your own website.
When you EXPORT using phpMyAdmin it is basically taking what is in the database and creating a text file of its contents that you can save for backup. If you want to restore the backup, go into phpmyadmin and paste that text file into SQL and it will put it back.
There are PHP commands to use to retrieve, and store data from your database. I recommend you look at the php website for mysql functions.
There are some good examples there.

Is it possible to create databases programmatically using DBX?

Looks like the TSQLConnection only connects to existing databases, and I could not find another component that allows me to send commands to the database server.
I'm using Delphi 2009 with Firebird and MSSQL.
One idea that came was to connect to a system database (master or tempdb in MSSQL for example) and then send create commands to the server. This could be an option for MSSQL, but I'm not sure for Firebird.
I'm also aware of the new DBX metadata in Delphi 2009, but I couldn't find a way to create databases using it. All examples I've found is to modify existing databases.
Yes, you can. dbExpress now includes a powerful set of meta-data classes for doing just that.
Steve Shaughnessy gives a good introduction here.
Erick if you use Devart drivers you can connect without the databasename parameter and send the t-sql create database command.
dbExpress included in Delphi uses a "least common denominator" strategy. Information like query statistics which is available through native drivers is invisible with dbExpress. (Maybe I should ask a question like "Which feature in alternative dbExpress implementations made you switch?")
You can execute "CREATE DATABASE ..." on both databases with standard TSQLQuery.
Note that syntax differes between these two. Since dbx is lightweight lib, this SQL and DB specific action probbably will never be fully supported. It leaves you with SQL.
With Delphi 2007/2009 comes DBX4. You may use the low level structures there to create database programmatically. Look in dbxcommons.pas
You can send a "CREATE DATABASE" script through any connection (ADO, OLEDB, ODBC, etc) opened on any server (or even ms-access files) as long as it follows the specific server DDL syntax.

Resources