Thesis Java

Topics: Microsoft Access, Text file, Microsoft Pages: 5 (512 words) Published: June 23, 2013
Source Code:

/**
Program Name: Final.java
Programer: hector C. Mañalac Jr.
Date Written: March 19, 2013
**/

import java.sql.*;
import java.io.*;
import java.lang.*;
public class Final_Exam
{

//
public static void CreateTable(String Filename)throws IOException {
Connection acon = null;
try
{
Class.forName("sun.jdbc.odbc.Jd1bcOdbcDriver");
acon = DriverManager.getConnection("jdbc:odbc:Final_Exam");

// Creating a database tablwe
Statement st = acon.createStatement();
int countIndex = st.executeUpdate("CREATE TABLE "+Filename+" (" + " Context VARCHAR(40))"); System.out.println("| Table has been created |"); st.close();
acon.close();
}
catch (Exception e)
{
System.out.println(“Overwriting... ");
}
}
public static void CreateFile(String txtFilename) throws IOException { File n;
n = new File(txtFilename+".txt");
if(!n.exists()){
n.createNewFile();
System.out.println("| " + txtFilename + " has been created to the directory |"); }
FileWriter fw = new FileWriter(n,true);
BufferedWriter bfw = new BufferedWriter(fw);

// write the marker
bfw.newLine();
bfw.newLine();
bfw.write("Submitted by:Hector C. Mañalac Jr.");
bfw.newLine();
bfw.write("Submitted to: Joel D. Canlas, MIT, MBA, CCTTA");
bfw.close();

}

public static void TableWrite(String txtFilename, String Filename)throws IOException {

Connection iCon = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
iCon = DriverManager.getConnection("jdbc:odbc:Final_Exam");
Statement st = iCon.createStatement();
FileInputStream fStream = new FileInputStream(txtFilename+".txt"); BufferedReader in = new BufferedReader(new InputStreamReader(fStream));

String lines;

int a = state.executeUpdate("Delete from "+Filename);
while (in.ready()){
lines = in.readLine();
int c = state.executeUpdate("INSERT INTO "+Filename+" (Context)"+ " VALUES ('"+strLine+"')"); }
in.close();
st.close();
iCon.close();
}
catch (Exception e){
System.out.println("File Input Error!");
}
}
public static void main(String [] args) throws IOException
{
Connection xCon = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
xCon = DriverManager.getConnection("jdbc:odbc:Final_Exam");
BufferedReader z = new BufferedReader(new InputStreamReader(System.in)); int ans;
do
{
System.out.println("File Input/Output with Microsoft Access"); System.out.println("[1] Text File to Microsoft Access Database"); System.out.println("[2] Microsoft Access Database to Text File"); System.out.print("\n Choose a process: ");

String vari = z.readLine();
ans = Integer.parseInt(vari);
if(ans>2||ans<1)
{
System.out.println("Invalid Input! Please Try Again! ");
Thread.sleep(2000);
}
}while(ans>2||ans<1);

if (ans==1)
{
String strWrite,strCopy;

System.out.println("Text File to Microsoft Access Database"); System.out.print("\n\n Enter textfile name to write from: "); strCopy = z.readLine();
CreateFile(strCopy);
System.out.print("\n Enter table name to write in: ");
strWrite = z.readLine();
CreateTable(strWrite);
TableWrite(strCopy,strWrite);
}
else
{
String strWrite,strCopy;
System.out.println("Microsoft Access Database to Text File"); System.out.print("\n Enter text file name to write in: ");
strWrite = z.readLine();
CreateFile(strWrite);
FileWriter fw = new FileWriter(strWrite+".txt",true);
BufferedWriter bfw = new BufferedWriter(fw);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
xCon = DriverManager.getConnection("jdbc:odbc:Finals_Floyd"); Statement st = xCon.createStatement();
System.out.print("\n\n Enter table name to write from: ");
strCopy = z.readLine();
// getting the data back
ResultSet res = state.executeQuery("SELECT * FROM "+strCopy); while (res.next()) {
bfw.write(res.getString("Context"));
bfw.newLine();
}
res.close();
st.close();
bfw.close();
}catch(Exception e){
System.out.println("Table doesn't exist");...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Java Essay
  • Thesis Essay
  • Java Javascript Essay
  • Comparison of Java, Javascript, Java Applets and Java Beans Essay
  • Java Project Essay
  • Java vs. C++ Essay
  • Java Ring Essay
  • Java Applets Essay

Become a StudyMode Member

Sign Up - It's Free