473,699 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help? JDBC or read from txt?

7 New Member
Hi guys, i've currently got an assignment, whereby, im supposed to create 2 classes, a Vehicle superclass, and a Taxi subclass.
Vehicle class needs to have Reg Number, model, price, and Taxi is supposed to inherit those from it.

I have done so, but now, it requires that all the data be stored in an array.

The final program, should be able to :
1) Add new taxi's into the program (which retains even after program exit)
2) Search for a particular taxi based on the given data
3) Display average price of the taxi.

My question is,
Should i store all the data in a database and read it from an array?
or
Store the data in a text file, and read the data from the array.

if i shud store the data in a database and read em from the array, how? i've read up on the JDBC introduction, i can have a MYSQL database in place, but whats the code for the array to read the data from database.

else

I've tried storing the data in text files, and reading it, but problem is, whenever i add a new entry into the text file, it doesnt just insert a new line of entry at the bottom of the txt file, but instead it overrides the old txt file thus losing all records.

Example of how the program should be like :

Please make a selection :
1) Add a new Taxi?
2) Search for old Taxi?
3) Display list of taxi in records?
4) Display average price of taxi?
5) Terminate the program
Enter Input :

------------- The List of Taxi -----------------------------------------------
Reg Num. Model Price TaxiCompany
------------------------------------------------------------------------------------
NY2314 Mercedes 20,000 ABC Company
DC1341 Volvo 15,000 DEF Company
TX5552 Ford 19,000 LJK Company
Feb 3 '07 #1
6 2049
horace1
1,510 Recognized Expert Top Contributor
I've tried storing the data in text files, and reading it, but problem is, whenever i add a new entry into the text file, it doesnt just insert a new line of entry at the bottom of the txt file, but instead it overrides the old txt file thus losing all records.
did you open the file with append set true so new data would be added on the end of the file?
Feb 4 '07 #2
xdeath
7 New Member
did you open the file with append set true so new data would be added on the end of the file?
um nope? im not exactly all so good with java, as i just started learning, and our lecturer already expects us to be able to do all this stuff, when we only just finished the chapter on inheritance. as for the code to save to file, i got it from googling around.

hm, as for arrays, is it possible to read lots of data from a database? as in, many fields? i was thinking like 4 fields (price, model, reg num, speed) = a 4 dimensional array? or ?

whats the best way to approach this using arrays as its a req for the assignment
I'm still thinking of how i'm gonna output as well as input all these data into an array.

thanks for the reply/
Feb 4 '07 #3
r035198x
13,262 MVP
um nope? im not exactly all so good with java, as i just started learning, and our lecturer already expects us to be able to do all this stuff, when we only just finished the chapter on inheritance. as for the code to save to file, i got it from googling around.







hm, as for arrays, is it possible to read lots of data from a database? as in, many fields? i was thinking like 4 fields (price, model, reg num, speed) = a 4 dimensional array? or ?







whats the best way to approach this using arrays as its a req for the assignment



I\\\'m still thinking of how i\\\'m gonna output as well as input all these data into an array.







thanks for the reply/


You don\\\'t need a 4d array. You use the classes that you wrote for temporary store of the values when retrieving the data from the file or from the database. First, howver, decide on whether you want to use a database or a file(The choice depends on your knowledge of these things so far.) If you decisde to use a file, you should serialize your classes so you can store whole objects of them.
Feb 5 '07 #4
xdeath
7 New Member
You don\\\'t need a 4d array. You use the classes that you wrote for temporary store of the values when retrieving the data from the file or from the database. First, howver, decide on whether you want to use a database or a file(The choice depends on your knowledge of these things so far.) If you decisde to use a file, you should serialize your classes so you can store whole objects of them.
i see, hm, im thinking of a database, seeming that reading from a file seemed to prove much problems when writing to the file for me, as well as the problem of reading. is there any where i can get more knowledge on those databases as well as code examples and explanations besides from the java.sun website? thanks again for the reply
Feb 6 '07 #5
r035198x
13,262 MVP
i see, hm, im thinking of a database, seeming that reading from a file seemed to prove much problems when writing to the file for me, as well as the problem of reading. is there any where i can get more knowledge on those databases as well as code examples and explanations besides from the java.sun website? thanks again for the reply
If you are covering them in class that should not be a problem, you can always ask any questions here if you get any problems. However, if you haven't been introduced to jdbc in class yet then you might as well use the file option for this exercise.
Feb 6 '07 #6
xdeath
7 New Member
If you are covering them in class that should not be a problem, you can always ask any questions here if you get any problems. However, if you haven't been introduced to jdbc in class yet then you might as well use the file option for this exercise.
well, uh the problem is, im doing e-study, which is fully online based, and apparently, we arent being taught much -.- neither do the course content has anything regarding reading/writing from/to files. which is actually the reason why im posting here. we're expected to do something that we arent even taught. and yea, we're not covering any of the above in class, only classes, inheritance, basic logical exp, so far.
Feb 7 '07 #7

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

Similar topics

0
4490
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web Server 6.1 with the SQL Server 2000 JDBC Driver. The background: 1. I have downloaded the SQL Server 2000 JDBC Driver and installed it on the web server.
1
6553
by: jdavis999x | last post by:
I have spent a good deal of time looking for how to connect an applet to a remote database (MS Access) using JDBC, as yet I have found no solid solution!! According to some books I have read the url takes the format of "jdbc:odbc://ipaddress:port/MS_Access/DBName" I am working with jbuilder and this does not work I am able to connect when i use "jdbc:odbc:DBNAME"
0
1493
by: Raquel | last post by:
Is anyone aware of a website/documentation which has a one to one comparision of corresponding programming features available in JDBC Vs SQLj. For example: CONCURRENCY: - JDBC: set through resultSetConcurrency constant in the constructor for Statement/PreparedStatement. It can be ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
1
6525
by: sid_mulpuru | last post by:
I am trying to read data from a DB2 Blob Data type Field (using wsad 5.1.0) using getBlob() which when executed gives an SQL Exception 2005-01-07 15:48:40,506 ERROR - Error in servlet:xxxxx.jsp initiateDownloadFri Jan 07 15:48:39 CST 2005com.ibm.db2.jcc.a.SqlException: 1 (in debug mode exception called at rs =
1
2613
by: kommaraju | last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2 using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a error message of HTTP STATUS 500 my jdbc program is as follows import java.sql.*; import java.lang.*; import java.io.*; import java.util.*;
0
1223
by: yksoni | last post by:
we are working in IBM aglets 2.0.2 with mysql 4.0.2. When we try to access database through tahiti server i.e.aglets we get following error. java.net.SocketException MESSAGE: java.security.AccessControlException: access denied (java.net.SocketPer mission 127.0.0.1:3306 connect,resolve) STACKTRACE: java.net.SocketException: java.security.AccessControlException: access denied (j
5
11577
by: byahne | last post by:
We just went live today with a production SQL Server 2005 database running with our custom Java application. We are utilizing the jTDS open source driver. We migrated our existing application which was using InterBase over to SQL Server. To minimize the impact to our code, we created a stored procedure which would allow us to manage our primary key IDs (mimicing the InterBase Generator construct). Now that we have 150+ users in the...
3
22836
by: Anoop | last post by:
Is it true that there are no type 4 jdbc drivers to connect to a DB2 server v7.1? The DB2 server is hosted on ACF2 (OS/390). We would be connecting from windows and solaris boxes. If it is true, what are my options? Will I have to install db2 connect on every client machine that needs to connect to the DB2 servers? Is the DB2 Connect freely available or will we have to purchase it? I have also read on this group that we can install DB2...
2
6669
by: anokun7 | last post by:
Hi, I am connecting to a DB2 v7.1 server from windows using JDBC type 2 (I figured out that type 4 is only for 8 and upwards). I used DB2 Connect to create a system DSN and seem to be able to connect fine using db2connect and run queries etc. The problem is when I try to use my java application to connect using the same DSN. The way the db has been configured is that I am
0
6514
by: neuraljay | last post by:
hi everyone. I am trying to build a jsp using webwork, hibernate and mysql. And right now I am doing its unit testing. Everytime I run the test I am getting this error: Error JDBC exception on Hibernate data access; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access; nested exception is...
0
8691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7755
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6536
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.