求助 --帮帮忙,谢谢 -_-

beyond_967 2003-04-17 05:42:38
我目前在学习java, 想用java做个小程序. 图书馆管理系统, 想用集合类模拟底层实现,不用jdbc(因为没学呢)
现在想求助各位老大, 我的思路很乱,不知道究竟应该怎么去具体编写. 那位老大能指点一二. 小弟感激不尽!!! -_-
...全文
21 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
beyond_967 2003-04-18
  • 打赏
  • 举报
回复
多谢 newman0708 的支持, 我也在正在做, 等做好了 一定发给你,
我的email是 liuzhiyao32@peoplemial.com.cn
其实我也知道等学完 jdbc和jsp了以后会很容易就做出来,但是我想通过这个模拟一下底层的具体实现,而且一直在用 Editplus的编译器,呵呵 是不是比较傻. -_-
newman0708 2003-04-17
  • 打赏
  • 举报
回复
xml编程,看好了!简单的。
这个是DOM,上面那个是JDOM.上面那个内存比较耗。

看看这个! DOM

http://expert.csdn.net/Expert/topic/1425/1425570.xml?temp=.6834223
newman0708 2003-04-17
  • 打赏
  • 举报
回复
我写了这么多,你做好了发一份给我,别忘了。

newman19800708@eastday.com
newman0708 2003-04-17
  • 打赏
  • 举报
回复
谁说做了成,我帮你up一下。

xml编程,看好了!简单的。


package xml_study;

import org.jdom.*;
import org.jdom.output.*;
import org.jdom.input.*;
import java.io.*;
import java.util.*;

/**
* 是如今第二先进
* 读写xml到文件
*
* NOTICE: 1.在默认情况下,JDOM的Element类的getText()这类的方法不会过滤空白字符,
* 如果你需要过滤,用setTextTrim() 。
*
* 2.只有源文件中是没有空头(空格<...>),才可以保证输出中格式准确
*/
public class TestJDOM{
Document m_Document;
String m_FilePath;
Element m_Root;

TestJDOM(String filepath)throws Exception{
this.setFilePath(filepath) ;
}

public void setFilePath(String filepath)throws Exception{
this.m_FilePath =filepath;
SAXBuilder sb = new SAXBuilder();
this.m_Document=sb.build(new FileInputStream(this.m_FilePath));
this.m_Root =this.m_Document .getRootElement() ;
}

/**
* return xml root
*/
public Element getRoot(){
return this.m_Root;
}

/**
* must have a model element
* @param parent
* @param childname -currentnode name
* @param table
*/
public void addChild(Element parent,String childname,Hashtable table){
Element CurrentNode=new Element(childname);
Enumeration enum=table.keys() ;
while (enum.hasMoreElements() ) {
String szkey=(String)enum.nextElement();
String szValue=(String)table.get(szkey);
Element node=new Element(szkey);
node.setText(szValue);
CurrentNode.addContent(node);
}
parent.addContent(CurrentNode);
}

/**
* not useful on the whole
* @param element
* @param attr
*/
public void setAttribute(Element element,Attribute attr){
element.addAttribute(attr);
}

/**
* end the operator
* @param outputfilepath
* @throws Exception
*/
public void write(String outputfilepath)throws Exception{
String indent = "\t";//小心,注意
boolean newLines = true;
XMLOutputter outp = new XMLOutputter(indent,newLines,"GBK");
//outp.setTrimText(true);
outp.output(this.m_Document, new FileOutputStream(outputfilepath));
}

public void aaa(){



}


public static void main(String args[])throws Exception{
/**
* add content and add element
*//*
TestJDOM tj=new TestJDOM("bookList.xml");//bookList.xml

Element root=tj.m_Root ;
java.util.List books = root.getChildren(); //得到根元素所有子元素的集合
System.out.println("books: "+books.toString());
Element book = (Element)books.get(0); //得到第一个book元素(the first book)
//为第一本书添加一条属性
Attribute a = new Attribute("hot","true");
book.addAttribute(a);

Element author = book.getChild("author"); //得到指定的字元素
System.out.println("author: "+author.getText());
author.setText("王五"); //将作者改为王五
//或 Text t = new Text("王五");book.addContent(t);

Element price = book.getChild("price"); //得到指定的字元素
//修改价格,比较郁闷的是我们必须自己转换数据类型,而这正是JAXB的优势
price.setText(Float.toString(50.0f));

Element phone =new Element("电话");
phone.setText("56384478");
book.addContent(phone);

Element salary =new Element("年薪");
//salary.setText("2万");
book.addContent(salary);

Element salary1 =new Element("年薪1");
salary1.setText("1.5万");
salary.addContent(salary1);

Element salary2 =new Element("年薪2");
salary2.setText("0.5万");
salary.addContent(salary2);

Element age =new Element("age");
age.setText("2年");
book.addContent(age);
tj.write("bookListOutPut.xml");
*/

/**
* add a people
*/

TestJDOM tj=new TestJDOM("bookList.xml");//bookList.xml
Hashtable tb=new Hashtable();
tb.put("name","newman");
tb.put("age","24");
tb.put("性别","男");
tb.put("job","student");
tb.put("tel","88888888");
tj.addChild(tj.m_Root ,"people",tb);

Attribute attr=new Attribute("year","1980");
tj.getRoot().getChild("people").addAttribute(attr);
tj.write("bookListOutPut.xml");



/**
* delete attribute
*/
/*
TestJDOM tj=new TestJDOM("bookListOutPut.xml");//bookList.xml
String attryear=tj.getRoot().getChild("people").getAttribute("year").getValue();
System.out.println("year="+attryear);
tj.getRoot().getChild("people").removeAttribute("year") ;
*/


/**
* delete element
*/
/*
TestJDOM tj=new TestJDOM("bookListOutPut.xml");//bookList.xml
String attryear=tj.getRoot().getChild("people").getName();
System.out.println("element people="+attryear);
tj.getRoot().removeChild("people");
*/

/**
* Namespace
* 未完,待续!
*//*
TestJDOM tj=new TestJDOM("bookList.xml");//bookList.xml
String str1=tj.m_Root.getChild("book").getChild("name").getNamespace().toString() ;
System.out.println("Namespace: "+str1);
str1=tj.m_Root.getNamespacePrefix();
System.out.println("m_Root NamespacePrefix: "+str1);

str1=tj.m_Root.getChild("book").getChild("name").getNamespace().getPrefix() ;
System.out.println("getChild getPrefix: "+str1);
*/




/**
* comment
*/
/*
TestJDOM tj=new TestJDOM("bookList.xml");//bookList.xml
tj.m_Root.getChild("book").addContent(new Comment("This is comment of book1.")) ;
tj.m_Root.getChild("book").addContent(new Comment("This is comment of book2.")) ;
tj.write("bookListOutPut.xml");
*/
}

}



//bookList.xml
/*
<?xml version="1.0" encoding="GBK"?>

<bookList>

<book>

<name>Java编程入门</name>

<author>张三</author>

<publishDate>2002-6-6</publishDate>

<price>35.0</price>

</book>

<book>

<name>XML在Java中的应用</name>

<author>李四</author>

<publishDate>2002-9-16</publishDate>

<price>92.0</price>

</book>

</bookList>
*/

/*

执行结果bookListOutPut.xml:

<?xml version="1.0" encoding="GBK"?>

<bookList>

<book hot=”true”>

<name>Java编程入门</name>

<author>50.0</author>

<publishDate>2002-6-6</publishDate>

<price>35.0</price>

</book>

<book>

<name>XML在Java中的应用</name>

<author>李四</author>

<publishDate>2002-9-16</publishDate>

<price>92.0</price>

</book>

</bookList>

<?xml-stylesheet href="bookList.html.xsl" type="text/xsl"?>

*/





newman0708 2003-04-17
  • 打赏
  • 举报
回复
只是练习而已,所以程序的好坏,以及设计的怎样都 没有什么关系,只是用来练兵吧了。

精神上支持你,我也正在考虑这个问题。

下面这个类我还没有写完,送给你吧(如果你要用Text SQL)

别忘记写完后,发一份给我,让我也看看。

newman19800708@eastday.com



import java.util.*;
import com.newman.io.FileReadWrite;
import com.newman.lang.MyString;
import com.newman.lang.StringToken;

/**
* <p>Title: This follow is newman's writing</p>
* <p>Description: I want better writing ,instead of best one!</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Shu</p>
* @author Newman
* @version 1.0
*/


/**
* 查询,写入函数没有实现
* 觉得没有必要写这个类,实现sql查询太复杂了。
*/

/**
* This is the core class.
* Function:
* 1.It can read the file and input the content into the memory in the way of hashtable.
* Hashtable contains some vectors , just the columns.
* So the user can query the content in the certain column .
* 2.It also can save the changes back to the text.
* So the user can modify the content .
*/
public class TextSQL {

String m_szFileName;//database filename
Hashtable m_Table;//database :store the vector
String m_szSeparator;//string separator
Vector m_vColumn;//the column vector
String m_ENTER="\r\n";

public TextSQL(String filename, String separator) {
this.m_szFileName =filename;
this.m_Table =new Hashtable();
this.m_szSeparator=separator;
this.m_vColumn =new Vector();
}

/**
* Load into memory
*/
public void loadInData() {
if(MyString.Assert(this.m_szFileName)&&MyString.Assert(this.m_szSeparator)){
FileReadWrite frw=new FileReadWrite(this.m_szFileName);
Enumeration enum=frw.getContentEnumeration();
boolean bflag=true;//create is true
while(enum.hasMoreElements()){
StringToken st=new StringToken((String)enum.nextElement(),this.m_szSeparator);
ArrayList list=new ArrayList();
list=st.workString();//get the data in line
if(list==null)//the file is null
return ;
int ColumnCount=list.size();

if(bflag){//at the first time
for(int i=0;i<ColumnCount;i++ ){
Vector v=new Vector();
this.m_Table .put(list.get(i),v);
this.m_vColumn .add(list.get(i)) ;//read the column
}
bflag=false;
}
else{
Enumeration enum2=this.m_Table.elements();
int i=0;
while(enum2.hasMoreElements()){
Vector v2=(Vector)enum2.nextElement();
v2.add(list.get(i));
i++;
}
}
}
}
else{
System.out.println("The database filename hasn't been defined!");
return;
}
}

/**
* set the separator
* @param separator
*/
public void setSeparator(String separator){
this.m_szSeparator =separator;
}

/**
* realize the queries
* @param column -the column
* @param command -int,string,boolean
* @return -result vector
*
* example:
-int :age<50 turn to float
-string:name='tom' , name like 'tom'
-boolean:gender=true
*
* ruler:select

*-----------------
id name age sex
1 tom 13 true
2 jack 23 false
3 rose 44 true
4 peter 22 false
5 kate 12 true

hashtable
id vectorid
1,2,3,4,5
name vectorname
tom,jack,rose,peter,kate
age vectorage
13,23,44,22,12
sex vectorsex
true,false,true,false true

*---------------return
*
*
*
*/
public Vector queryData(int column, String command){
return null;

}

public void storeData(){
String szdata="";


}

/**
* get a recorder by index
* @param index the index of the vector
* @return vetor(a recorder)
*/
private Vector getRecorder(int index){
Vector v=new Vector();
Enumeration enum=this.m_Table.elements() ;
while(enum.hasMoreElements()){
Vector v2=(Vector)enum.nextElement() ;
v.add(v2.elementAt(index));
}
return v;
}

/**
* get printing string
* @param result -vector int vector,full records
* @return
*/
private String getPrintString (Vector result){
Enumeration enum=this.m_vColumn.elements();
String recordtitle="";
while(enum.hasMoreElements() ){
recordtitle=recordtitle+(String)enum.nextElement() +this.m_szSeparator;
}
recordtitle=recordtitle+this.m_ENTER;

String records="";//all records
int count=this.getRecordCount();

for(int i=0;i<count;i++){
Vector v=this.getRecorder(i);
records=records+this.getVectorString(v)+this.m_ENTER;
}
records=recordtitle+records;
return records;
}

/**
* get records count
* @return count
*/
public int getRecordCount(){
Enumeration enum=this.m_Table.elements();
Vector v=new Vector();
if(enum.hasMoreElements()){
v=(Vector)enum.nextElement();
}
return v.size() ;
}

/**
*get string from vector(single vector,elements are object ,not vector)
* @param vector
* @return
*/
private String getVectorString (Vector vector){
Enumeration enum=vector.elements() ;
String records="";
while(enum.hasMoreElements()){
records=records+(String)enum.nextElement()+this.m_szSeparator;
}
return records;
}

public String getType(){
return "";
}
//--------------------------------debug start
/**
* show all the data in the result
* @param result -vector int vector,full records
*/
private void printResult(Vector result){
String records=this.getPrintString(result);
System.out.println(records);
}

/**
* spy the data in the hashtable
*/
private void spyHashTable(){
Enumeration enum=this.m_Table.elements();
Vector vector=new Vector();
while(enum.hasMoreElements()){
Vector v=(Vector)enum.nextElement() ;
vector.add(v);
}
this.printResult(vector) ;
}

/**
* spy the data in the vector
*/
private void spyVector(Vector vector){
String records=this.getVectorString(vector);
System.out.println(records);
}

//-------------------------------------debug end

public static void main(String[] args) {
TextSQL textSQL1 = new TextSQL("TextSQL.txt"," ");
textSQL1.loadInData();
textSQL1.spyHashTable() ;//spy the hashtable

Vector v=textSQL1.getRecorder(2);
textSQL1.spyVector(v) ;//spy the vector

textSQL1.spyVector(textSQL1.m_vColumn );//spyVector

System.out.println("Records Count: "+textSQL1.getRecordCount());//get Record Count
/*
System.out.println(Float.parseFloat("35"));
System.out.println(Float.parseFloat("35")>20);
*/

}
}
javafounder 2003-04-17
  • 打赏
  • 举报
回复
数据量小的话,可以考虑用XML文件存储数据,不过你又得学关于XML方面的编成了,
更麻烦,哎,看来,这个程序你是做不成了:)
wobensuren 2003-04-17
  • 打赏
  • 举报
回复
还是学学数据库 可以是jsp+jdbc 很简单的
nick19800707 2003-04-17
  • 打赏
  • 举报
回复
只是练习而已,所以程序的好坏,以及设计的怎样都 没有什么关系,只是用来练兵吧了。

精神上支持你,我也正在考虑这个问题。

superLee 2003-04-17
  • 打赏
  • 举报
回复

还是先学java的数据库编程后,再尝试这个例子吧!
moumouren 2003-04-17
  • 打赏
  • 举报
回复
不用数据库的话,你准备吧数据写在文件里,会很累的

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧