Guest User

Untitled

a guest
Dec 13th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import java.sql.*;
  2. public class UserLogin {
  3. public static void main(String[] args) {
  4. try {
  5. // Load MS accces driver class
  6. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  7.  
  8. // C:\databaseFileName.accdb" - location of your database
  9. String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "C:\AGENDAS\Agenda.accdb";
  10.  
  11. // specify url, username, pasword - make sure these are valid
  12. Connection conn = DriverManager.getConnection(url, "Java2016", "Java2016");
  13.  
  14. System.out.println("Connection Succesfull");
  15. } catch (Exception e) {
  16. System.err.println("Got an exception! ");
  17. System.err.println(e.getMessage());
  18.  
  19. }
  20. }
  21. }
  22.  
  23. sun.jdbc.odbc.JdbcOdbcDriver
  24.  
  25. jdbc:odbc:<data-source-name>[<attribute-name>=<attribute-value>]*
  26.  
  27. jdbc:odbc:sybase
  28. jdbc:odbc:mydb;UID=me;PWD=secret
  29. jdbc:odbc:ora123;Cachesize=300
  30.  
  31. private Connection con ;
  32.  
  33. private Statement stmt;
  34.  
  35.  
  36. public void connect ( String path ){
  37.  
  38. try {
  39. Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
  40.  
  41. this.con = DriverManager.getConnection(path, "", "");
  42.  
  43. this.stmt = con.createStatement();
  44.  
  45. } catch (SQLException ex) {
  46. System.err.println("SQLException: " + ex.getMessage());
  47. }
  48. catch (ClassNotFoundException e) {
  49.  
  50. System.err.println("classnotfoundException: " + e.getMessage());
  51.  
  52.  
  53. }
  54. }
Add Comment
Please, Sign In to add comment