Retrieve from Microsoft Excel document for CodeGenerator?
Basically, I have a code generator that I've made in java (that generates code for a Visual Basic Quiz program I'm making) that I would like to make more effecient by using it with a database.
If anyone is interested, this is what it looks like:
Code :
import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Vector;
public class codegen {
static int qnum = 1;
static int snum = 1;
public static void main(String[] a) {
Vector victor;
int size = 10;
victor = new Vector(size);
for (int i = 0; i < size; i++)
victor.addElement(new Integer(i));
try {
PrintStream out = new PrintStream(new FileOutputStream(
"OutFile.txt"));
for (int i = 0; i < size; i++)
while (snum <= 15){
if (qnum <= 71){
out.println("ElseIf Randq = " + qnum + " And sec" + snum + "(" + qnum + ") < 3 Then");
out.println("answrstrng = ''");
out.println("If usrinput = answrstrng Then");
out.println("Correct.Text += 1");
out.println("sec" + snum + "(" + qnum + ") += 1");
out.println("Else");
out.println("Incorrect.Text += 1");
out.println("sec" + snum + "(" + qnum + ") -= 1");
out.println("canswer.Text = answrstrng");
out.println("End If");
++qnum;
}
else {
qnum = 1;
snum++;
}
}
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
It would make things a lot easier for me, and make the code generator complete, if where it says
Code :
out.println("answrstrng = ''");
i could replace the '' with text from the cell of an excel document. For example, if cell A1 said "Fiji" in the document, it would print answrstrng = "fiji".
I don't really know anything about Java databases, so if there's another way I should do this outside of microsoft excel, information on that would help me too.
Thanks!
Re: Retrieve from Microsoft Excel document for CodeGenerator?
I'm confused as to what you are asking...do you wish to use Excel, or a relational database (quite different things)? For excel, you can use 3rd party libraries such as Apache POI to read and write the file. For a relational database, you should learn SQL (and there are many options to choose from: Derby, MySQL, PostgreSQL, etc...)