Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class UserLogin {
- public static void main(String[] args) {
- try {
- // Load MS accces driver class
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- // C:\databaseFileName.accdb" - location of your database
- String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "C:\AGENDAS\Agenda.accdb";
- // specify url, username, pasword - make sure these are valid
- Connection conn = DriverManager.getConnection(url, "Java2016", "Java2016");
- System.out.println("Connection Succesfull");
- } catch (Exception e) {
- System.err.println("Got an exception! ");
- System.err.println(e.getMessage());
- }
- }
- }
- sun.jdbc.odbc.JdbcOdbcDriver
- jdbc:odbc:<data-source-name>[<attribute-name>=<attribute-value>]*
- jdbc:odbc:sybase
- jdbc:odbc:mydb;UID=me;PWD=secret
- jdbc:odbc:ora123;Cachesize=300
- private Connection con ;
- private Statement stmt;
- public void connect ( String path ){
- try {
- Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
- this.con = DriverManager.getConnection(path, "", "");
- this.stmt = con.createStatement();
- } catch (SQLException ex) {
- System.err.println("SQLException: " + ex.getMessage());
- }
- catch (ClassNotFoundException e) {
- System.err.println("classnotfoundException: " + e.getMessage());
- }
- }
Add Comment
Please, Sign In to add comment