Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Connects to a remote MS-Access DB using JDBC/UCanAccess API.
- *
- * ADDITIONAL JARS REQD:
- *
- * commons-lang-2.6.jar
- * commons-logging-1.1.1.jar
- * hsqldb.jar
- * jackcess-2.1.0.jar
- * ucanaccess-2.0.9.5.jar
- *
- */
- package miscellaneous;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- /**
- * @author Sandeep Chatterjee
- *
- */
- public class ConnectRemoteDB {
- /**
- * @param args
- */
- public static void main(String[] args) {
- initializeConnection();
- }
- /**
- * Initializes remote database connection and inserts a record and closes the connection.
- */
- private static void initializeConnection() {
- System.out.println("Attempting Database Connection...");
- Connection connection = null;
- PreparedStatement preparedStatement = null;
- try {
- connection = DriverManager
- .getConnection("jdbc:ucanaccess:////192.168.1.181/Prosenjit_H/TestDB.mdb");
- System.out.println("CONNECTION ESTABLISHED....");
- String insertTableSQL = "INSERT INTO Table1" + "(Name) VALUES"
- + "(?)";
- preparedStatement = connection.prepareStatement(insertTableSQL);
- preparedStatement.setString(1, "Santanu");
- preparedStatement.executeUpdate();
- System.out.println("RECORD INSERTED...");
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- try {
- connection.close();
- System.out.println("CONNECTION CLOSED...");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment