Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Java connection to MS Access

Java connection to MS Access

Scheduled Pinned Locked Moved Web Development
databasequestionjavacomgame-dev
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Red Sunday
    wrote on last edited by
    #1

    I am running code to connect to a database that stores theme data for a video game. This is the code I am running: import java.sql.*; //import all the JDBC classes import java.sql.*; import java.io.IOException; public class GetAccessToDatabase { static Connection conn; final String URL = "game.mdb"; public boolean OpenConnection() throws SQLException, IOException { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (Exception e) { System.out.println("Could not load the driver."); e.printStackTrace(); return false; } try { conn = DriverManager.getConnection ("jdbc:odbc:" + URL, "", ""); return true; } catch (Exception e) { System.err.println("Problems with get connection sent to "+URL+ ": "+e.getMessage()); } return false; } public void CloseConnection() throws SQLException { conn.close(); } public static void main(String args[]) { try { GetAccessToDatabase connect = new GetAccessToDatabase(); if(connect.OpenConnection()) { Statement stmt = conn.createStatement(); /* stmt.executeUpdate("INSERT INTO student " + "(name, studentNumber, class, major) " + "VALUES ('Smith', '17', 1, 'CS')"); */ // more database statements connect.CloseConnection(); } } catch (Exception e) { System.err.println("problems with SQL sent from "+"static main function"+ ": "+e.getMessage()); } } } And this is the message I receive from the exception thrown: Problems with get connection sent to game.mdb: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Basically, it doesn't see the game.mdb which I have placed in the local directory. I believe it is expecting some type of table in SQL, but how do I do that in MS Windows from Access? Any and all help would be greatly appreciated. Thank you, Red Sunday ----------------- http://www.zachcalvert.com

    D 1 Reply Last reply
    0
    • R Red Sunday

      I am running code to connect to a database that stores theme data for a video game. This is the code I am running: import java.sql.*; //import all the JDBC classes import java.sql.*; import java.io.IOException; public class GetAccessToDatabase { static Connection conn; final String URL = "game.mdb"; public boolean OpenConnection() throws SQLException, IOException { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (Exception e) { System.out.println("Could not load the driver."); e.printStackTrace(); return false; } try { conn = DriverManager.getConnection ("jdbc:odbc:" + URL, "", ""); return true; } catch (Exception e) { System.err.println("Problems with get connection sent to "+URL+ ": "+e.getMessage()); } return false; } public void CloseConnection() throws SQLException { conn.close(); } public static void main(String args[]) { try { GetAccessToDatabase connect = new GetAccessToDatabase(); if(connect.OpenConnection()) { Statement stmt = conn.createStatement(); /* stmt.executeUpdate("INSERT INTO student " + "(name, studentNumber, class, major) " + "VALUES ('Smith', '17', 1, 'CS')"); */ // more database statements connect.CloseConnection(); } } catch (Exception e) { System.err.println("problems with SQL sent from "+"static main function"+ ": "+e.getMessage()); } } } And this is the message I receive from the exception thrown: Problems with get connection sent to game.mdb: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Basically, it doesn't see the game.mdb which I have placed in the local directory. I believe it is expecting some type of table in SQL, but how do I do that in MS Windows from Access? Any and all help would be greatly appreciated. Thank you, Red Sunday ----------------- http://www.zachcalvert.com

      D Offline
      D Offline
      David Salter
      wrote on last edited by
      #2

      You need to register an ODBC datasource and pass the name of that to the getConnection() method rather than the name of the access file.


      Store your favourite bookmarks online: my-faves.co.uk

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups