Hello,
I am writing an application and I am having a bit of a quandry, first off, what type of database should I be using to store the data? There will be potentially upwards of 1000 rows of data or so. My first thought was MySql, but then I thought about it and, unless im wrong, this will mean that anyone that wants to use the program must also goto mysql, download the database, then come back and run a setup to add the tables into mySql. This seems like alot of extra steps, so I though maybe flatfile, but then there is no security, and even though the data is not vital or needs to be kept private, there still will be the passwords for the people logging in.
So I did some research and found XStream. This seems like it could work, but for the life of me I cannot figure out how to get it installed into Netbeans correctly.
I went to the "2 minute tutorial" and figured I would try it, so i found THIS example. I put Xstream into a library (and Xpps into a library as well) then added them to my project, i copied and pasted the sample code into netbeans like so:
Xstreamtest
ShipTo
Item
ShipOrder
and it shows no errors but when i try to run it i get this:
Line 37 of Xstreamtest is this btw:
So my question(s) are this:
1: What should I be using to store data?
2: any idea what is wrong with the above?
Thank you for any help...
I am writing an application and I am having a bit of a quandry, first off, what type of database should I be using to store the data? There will be potentially upwards of 1000 rows of data or so. My first thought was MySql, but then I thought about it and, unless im wrong, this will mean that anyone that wants to use the program must also goto mysql, download the database, then come back and run a setup to add the tables into mySql. This seems like alot of extra steps, so I though maybe flatfile, but then there is no security, and even though the data is not vital or needs to be kept private, there still will be the passwords for the people logging in.
So I did some research and found XStream. This seems like it could work, but for the life of me I cannot figure out how to get it installed into Netbeans correctly.
I went to the "2 minute tutorial" and figured I would try it, so i found THIS example. I put Xstream into a library (and Xpps into a library as well) then added them to my project, i copied and pasted the sample code into netbeans like so:
Xstreamtest
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xstreamtest;
import com.thoughtworks.xstream.XStream;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Klaus
*/
public class Xstreamtest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Getting the Xstream
XStream xstream = Xstreamtest.getStream();
// Serializing the object to XML
ShipTo shipTo = Xstreamtest.getShipTo();
List<Item> listOfItems = Xstreamtest.getItems();
ShipOrder shipOrder = Xstreamtest.getShipOrder(shipTo, listOfItems);
// Serializing to the XML into one String, can create file if you want it.
String shipOrderXml = xstream.toXML(shipOrder);
// Display the XML created
System.out.println("The XML :");
System.out.println(shipOrderXml);
// Populating the obj again
ShipOrder shipOrder1 = (ShipOrder) xstream.fromXML(shipOrderXml);
ShipTo shipTo1 = shipOrder1.getShipto();
List<Item> listOfItems1 = shipOrder1.getItem();
System.out.println("-------------------------------");
System.out.println("- Desirializing to the object -");
System.out.println("-------------------------------");
System.out.println("Order Id : " + shipOrder1.getOrderid());
System.out.println("Order Person : " + shipOrder1.getOrderperson());
System.out.println("Ship To : " + shipOrder1.getShipto().getName());
System.out.println("Items : ");
for (Item item : listOfItems1) {
System.out.println("Title : " + item.getTitle());
System.out.println("Qtde. : " + item.getQuantity());
System.out.println("Price : " + item.getPrice());
System.out.println("Note : " + item.getNote());
System.out.println("-----------------------------------------");
}
}
public static XStream getStream() {
XStream xstream = new XStream();
xstream.alias("shipTo", ShipTo.class);
xstream.alias("item", Item.class);
xstream.alias("shipOrder", ShipOrder.class);
return xstream;
}
public static List<Item> getItems() {
List<Item> items = new ArrayList<Item>();
Item item = new Item();
item.setTitle("Item 01");
item.setPrice("10.00");
item.setQuantity("5");
item.setNote("This is the first item");
items.add(item);
item = new Item();
item.setTitle("Item 02");
item.setPrice("15.00");
item.setQuantity("7.50");
item.setNote("This is the second item");
items.add(item);
return items;
}
public static ShipTo getShipTo() {
ShipTo shipTo = new ShipTo();
shipTo.setName("Customer 01");
shipTo.setCity("City 01");
shipTo.setCountry("country 01");
shipTo.setAddress("Address 01");
return shipTo;
}
public static ShipOrder getShipOrder(ShipTo shipTo, List<Item> items) {
ShipOrder so = new ShipOrder();
so.setOrderid("Order number 01");
so.setOrderperson("Order to Person 01");
so.setShipto(shipTo);
so.setItem(items);
return so;
}
}
ShipTo
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xstreamtest;
public class ShipTo {
private String name;
private String address;
private String city;
private String country;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
Item
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xstreamtest;
public class Item {
private String title;
private String note;
private String quantity;
private String price;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
ShipOrder
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xstreamtest;
import java.util.List;
public class ShipOrder {
private String orderid;
private String orderperson;
private ShipTo shipto;
private List<Item> item;
public String getOrderid() {
return orderid;
}
public void setOrderid(String orderid) {
this.orderid = orderid;
}
public String getOrderperson() {
return orderperson;
}
public void setOrderperson(String orderperson) {
this.orderperson = orderperson;
}
public ShipTo getShipto() {
return shipto;
}
public void setShipto(ShipTo shipto) {
this.shipto = shipto;
}
public List<Item> getItem() {
return item;
}
public void setItem(List<Item> item) {
this.item = item;
}
}
and it shows no errors but when i try to run it i get this:
run:
The XML :
<shipOrder>
<orderid>Order number 01</orderid>
<orderperson>Order to Person 01</orderperson>
<shipto>
<name>Customer 01</name>
<address>Address 01</address>
<city>City 01</city>
<country>country 01</country>
</shipto>
<item>
<item>
<title>Item 01</title>
<note>This is the first item</note>
<quantity>5</quantity>
<price>10.00</price>
</item>
<item>
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory
<title>Item 02</title>
<note>This is the second item</note>
<quantity>7.50</quantity>
<price>15.00</price>
</item>
</item>
</shipOrder>
at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:57)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904)
at xstreamtest.Xstreamtest.main(Xstreamtest.java:37)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 5 more
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)
Line 37 of Xstreamtest is this btw:
ShipOrder shipOrder1 = (ShipOrder) xstream.fromXML(shipOrderXml);
So my question(s) are this:
1: What should I be using to store data?
2: any idea what is wrong with the above?
Thank you for any help...