Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1107
  • Last Modified:

ODBC:JDBC help

I have a java file that I use to connect to a MySql database, but now I want to use it to connect to an MS Access DB on my Windows desktop.  I have jdk 1.4.2 on my system.

Here is the error I'm getting upon compiling:

C:\Documents and Settings\Administrator\Desktop\JDBCTest\JdbcExampleAccess1.java:11: illegal escape character
      con = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Documents and Settings\Administrator\Desktop\quiz.mdb");
                                                                                                  ^
C:\Documents and Settings\Administrator\Desktop\JDBCTest\JdbcExampleAccess1.java:11: illegal escape character
      con = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Documents and Settings\Administrator\Desktop\quiz.mdb");
                                                                                                                         ^
C:\Documents and Settings\Administrator\Desktop\JDBCTest\JdbcExampleAccess1.java:11: illegal escape character
      con = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Documents and Settings\Administrator\Desktop\quiz.mdb");
                                                                                                                                       ^
C:\Documents and Settings\Administrator\Desktop\JDBCTest\JdbcExampleAccess1.java:11: illegal escape character
      con = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Documents and Settings\Administrator\Desktop\quiz.mdb");
                                                                                                                                               ^
4 errors

------------------------------------------------------

Here is a snippet of my code.  

import java.sql.*;

public class JdbcExampleAccess1 {

  public static void main(String args[]) {
    Connection con = null;

    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
      con = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Documents and Settings\Administrator\Desktop\quiz.mdb");


I know this has to be a syntax error in my DB URL, bc it is pointing to the forward slashes.  Any help would be appreciated! :)



0
gdlp2004
Asked:
gdlp2004
  • 2
2 Solutions
 
CEHJCommented:
Double up the backslashes
0
 
objectsCommented:
try this:

con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Documents and Settings\\Administrator\\Desktop\\quiz.mdb");
0
 
CEHJCommented:
gdlp2004, can you tell me why you have marked an answer as accepted that simply repeats the answer i'd already given?

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now