net.ucanaccess.console.Main Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ucanaccess Show documentation
Show all versions of ucanaccess Show documentation
An open source pure Java JDBC Driver implementation which allows Java developers and JDBC client programs (e.g., Open Office, Libre Office, Squirrel SQL) to read/write Microsoft Access databases.
/*
Copyright (c) 2012 Marco Amadei.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package net.ucanaccess.console;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import net.ucanaccess.util.Logger;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
public class Main {
private static boolean batchMode=false;
private Connection conn;
private boolean connected = true;
private BufferedReader input;
private String lastSqlQuery;
public Main(Connection conn, BufferedReader input) {
this.conn = conn;
this.input = input;
}
private static boolean hasPassword(File fl) throws IOException {
Database db;
try{
db = DatabaseBuilder.open(fl);
}catch(IOException e){
DatabaseBuilder dbb=new DatabaseBuilder();
dbb.setReadOnly(true);
dbb.setFile(fl);
db= dbb.open();
}
String pwd = db.getDatabasePassword();
db.close();
return pwd != null;
}
private static void lcProperties(Properties pr) {
Properties nb=new Properties();
for( Entry