Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package softwareEng;
- import java.sql.*;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class driver {
- public static void main(String[] args) throws IOException {
- // Build database
- String userName = JOptionPane.showInputDialog("Type in the username for your MySql database");
- String passWord = JOptionPane.showInputDialog("Type in the password for your MySql databse");
- buildDatabase(args[0], args[1], userName, passWord);
- Menu gui = new Menu(args[1], userName, passWord);
- } // ends main
- public static void buildDatabase(String inFile, String outFile, String userName, String passWord) throws IOException {
- Scanner inFile_1 = new Scanner(new FileReader(inFile));
- FileWriter outFile_1 = new FileWriter(outFile);
- try {
- String driverName = "org.gjt.mm.mysql.Driver";
- Class.forName(driverName);
- java.sql.Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/project", userName, passWord);
- DatabaseMetaData metadata = myConn.getMetaData();
- ResultSet rs = metadata.getTables(null,null,"Pets",null);
- if (!rs.next()) {
- while (inFile_1.hasNextLine()) {
- java.sql.Statement myStmt = myConn.createStatement();
- String input = inFile_1.nextLine();
- outFile_1.write(input);
- outFile_1.write('\n');
- myStmt.executeUpdate(input);
- }
- } // if table Pets doesnt exist, create it using input
- } catch (Exception exc) {
- JOptionPane.showMessageDialog(null, "Invalid Login");
- System.exit(0);
- }
- inFile_1.close();
- outFile_1.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement