473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQL Table Array Data Population for MySQL,DB2 and Oracle

Hi, All.

I am working on a project with another student that will be used on Oracle, MySWL and DB2 databases. We have completed all the basic functions, but I would like to see if we can improve on one aspect of the code.

Scenario: There are 5 bank tables
private final String[]
tableList = {"account" , "branch", "customer", "depositor", "loan", "borrower"};
There is a string array for the table schemas

private final String[]
tableSchema = {"CREATE TABLE ACCOUNT( BRANCH_NAME CHAR(10),ACCOUNT_NUMBER CHAR(5) ,BALANCE DECIMAL(3,0))",
"CREATE TABLE BRANCH (BRANCH_NAME CHAR(10),BRANCH_CITY CHAR(15), ASSETS DECIMAL(10,2))",
"CREATE TABLE CUSTOMER (CUSTOMER_NAME CHAR(10),CUSTOMER_STREET CHAR(20),CUSTOMER_CITY CHAR(15))",
"CREATE TABLE DEPOSITOR (CUSTOMER_NAME CHAR(10),ACCOUNT_NUMBER CHAR(5))",
"CREATE TABLE LOAN (BRANCH_NAME CHAR(10),LOAN_NUMBER CHAR(4) ,AMOUNT DECIMAL(10,2))",
"CREATE TABLE BORROWER ( CUSTOMER_NAME CHAR(10), LOAN_NUMBER CHAR(4))" };

And there are string arrays for the information to be inserted in the tables.

private final String[][]
tableRow = {
// Account table data
{"'Downtown','A-101',500",
"'Mianus', 'A-215', 700",
"'Perryridge', 'A-102', 400",
"'Round Hill', 'A-305', 350",
"'Perryridge', 'A-201', 900",
"'Redwood', 'A-222', 700",
"'Brighton', 'A-217', 750"},
// Branch table data
{"'Downtown','Brooklyn', 9000000",
"'Redwood','Palo Alto', 2100000",
"'Perryridge','Horseneck',1700000",
"'Mianus','Horseneck', 400000",
"'Round Hill','Horseneck',8000000",
"'Pownal','Bennington',300000",
"'North Town','Rye',3700000",
"'Brighton','Brooklyn', 7100000"},
// Customer table data
{"'Jones' ,'Main' ,'Harrison'",
"'Smith' ,'North' ,'Rye'",
"'Hayes' ,'Main' ,'Harrison'",
"'Curry' ,'North' ,'Rye'",
"'Lindsay' ,'Park' ,'Pittsfield'",
"'Turner' ,'Putnam' ,'Stamford'",
"'Williams' ,'Nassau' ,'Princeton'",
"'Adams' ,'Spring' ,'Pittsfield'",
"'Johnson' ,'Alma' ,'Palo Alto'",
"'Glenn' ,'Sand' ,'Hill Woodside'",
"'Brooks' ,'Senator' ,'Brooklyn'",
"'Green' ,'Walnut' ,'Stamford'"},
// Depositor table data
{"'Hayes' ,'A-102'",
"'Johnson' ,'A-101'",
"'Johnson' ,'A-201'",
"'Jones' ,'A-217'",
"'Lindsay' ,'A-222'",
"'Smith' ,'A-215'",
"'Turner' ,'A-305'"},
// Loan table data
{"'Downtown' ,'L-17' ,'1000'",
"'Redwood' ,'L-23' ,'2000'",
"'Perryridge' ,'L-15' ,'1500'",
"'Downtown' ,'L-14' ,'1500'",
"'Mianus' ,'L-93' ,'500'",
"'Round Hill' ,'L-11' ,'900'",
"'Perryridge' ,'L-16' ,'1300'"},
// Borrower table data
{"'Adams' ,'L-16'",
"'Curry' ,'L-93'",
"'Hayes' ,'L-15'",
"'Jones' ,'L-17'",
"'Smith' ,'L-11'",
"'Smith' ,'L-23'",
"'Williams' ,'L-17'"}
};

The current code supports the user selecting what they want to do by command line commands. Ex. Create [tablename];Load [tablename];Drop [tablename], etc.

I have the code to create “ALL’ of the tables, which works fine

case CREATE:
{
if (op.length < 2)
{
System.out.println("Error! can not " + op[0] + "table due to missing table name");
displayValidTable(tableList);
break;
}
tableName = op[1];
curTableCode = getTableCode(tableName.toLowerCase(), tableList);
switch (curTableCode){

case ALL:
for (int i=0;i < tableList.length;i++){
dbase.executeSQLdllQuery(tableSchema[i]);
}
dbase.closeConnection();
break;
Now here is my dilemma:

I would like to be able to use the current code structure to add a CASE ALL: to the loading of the information into the tables (see below) and to the dropping of all of the tables, without having the user name them individually.

Any ideas?

Load Table Code:

case LOAD:
{
if (op.length < 2)
{
System.out.println("Error! can not load table due to missing table name");
displayValidTable(tableList);
break;
}
tableName = op[1];
curTableCode = getTableCode(tableName.toLowerCase(), tableList);
LoadTable (dbase, tableName, tableRow[curTableCode]);
dbase.closeConnection();
break;
}
private void LoadTable(DbaseBean dbasel, String tableName, String tableRow[]){
dbasel.executeSQLdllQuery("DELETE FROM " + tableName);
for (int i=0; i < tableRow.length; i++)
{
dbasel.executeSQLdllQuery("INSERT INTO " + tableName + " VALUES (" + tableRow[i]+")");
}

DROP TABLE code:
case DROP:
{
if (op.length < 2)
{
System.out.println("Error! can not create table due to missing table name");
displayValidTable(tableList);
break;
}
tableName = op[1];
dropTable (dbase, tableName);
dbase.closeConnection();
break;
}
private void dropTable(DbaseBean dbasel, String tableName){
dbasel.executeSQLdllQuery("DROP TABLE " + tableName);
}

Thank you for any help you can provide.
Mar 6 '07 #1
0 2731

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Philip D Heady | last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use MySQL but at the office here we use Oracle and boy do I have alot to learn. I'm starting to hate it after using MySQL!! ...
4
by: MS | last post by:
Hi, In my Genetic Algorithm program, I have a class called Genome. Another class called GA has a class variable called 'population' which is an array of type Genome. One of the methods in GA,...
6
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm raid 5 on u320 perc raid...
0
by: Ali | last post by:
Hello, I have written a utility in C# using ODBC.NET. It can fetch information from a ODBC supported database table and copy it to the other ODBC supported DB table; provided the tables exist on...
2
by: Galina | last post by:
Hello I need to get data from 4 Oracle tables and combine them into a temporary table in my application. I get data using a pass-through query dynamically created in code: mySQL = "SELECT...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
4
by: spwpreston | last post by:
Hello, I am new to MySQL. I am trying to load from a text file to a table, and am having problems with the fields in the text file being translated to the correct fields in the TABLE. Right...
1
by: Jim | last post by:
Hi, I capture data from an none db source using perl and then every night I load the mysql table with the new data. Can someone explain to me the best way to do that? It takes 30 minutes or...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.