If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > run in my PC: Type 1 db driver Access / java[SE1.6] Desktop Applications, what I need

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-14-09, 09:47
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
run in my PC: Type 1 db driver Access / java[SE1.6] Desktop Applications, what I need

http://www.paphoscarhire.mobi/odbc-bridge2.jpg
desktop control panel settings, I have above URL (IMG) Settings
well, I need to run in my PC: Type 1 db driver Access / java[SE1.6] Desktop Applications, what I need to install ?

I refer for Type 1, JDBC-ODBC Bridge driver.... Is it needed install and Access 2003 ODBC driver (see URL) ...? How I understand if I already installed it(?) since I do not know ?

How to load driver in my program ? The below are correct for: Class.forName & DriverManager.getConnection ?
Code:
 class  ResultSetDemo    {
  public static void main (String  [ ] args)    {
    try {
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       Connection conn
          =DriverManager.getConnection("jdbc:odbc:RedWines");  // DSN=RedWines
       Statement  sttmnt  =  conn.createStatement (  );
I GET ERROR !
Code:
 C:\Users\User\Documents\TextBooks Data Files\The Web Warrior Guide to Web Database Technolo
gies, 1st Edition\extract\Chapter06\Chapter>java ResultSetDemo
[Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM claus
e.
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
        at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
        at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
        at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
        at ResultSetDemo.main(ResultSetDemo.java:10)


C:\Users\User\Documents\TextBooks Data Files\The Web Warrior Guide to Web Database Technolo
gies, 1st Edition\extract\Chapter06\Chapter>
Reply With Quote
  #2 (permalink)  
Old 11-14-09, 13:45
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
DriverManager call is correct.
Did you configure an ODBC source named RedWines in the system ? Having only an Access database named RedWines is not enough.

HTH
Laurent
Reply With Quote
  #3 (permalink)  
Old 11-14-09, 14:54
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
I havn't installed JDBC-ODBC Bridge driver or even ODBC driver for java

See the URL, I do not know if I have installed JDBC-ODBC Bridge driver or even ODBC driver for java, where found, and how understand if I have them ?
I make DSN as URL shows but I sure I do not have drivers where found themselves and installation instructions?
Reply With Quote
  #4 (permalink)  
Old 11-15-09, 03:18
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
sun.jdbc.odbc.JdbcOdbcDriver is in your classpath, if not, "Class.forName()" would have thrown a ClassNotFoundException. This call looks doing nothing, but instructs the class loader to fetch the desired class.
The problem is with "jdbcdbc:RedWines" in [ODBC Microsoft Access Driver] Syntax error in FROM clause.

So it's not a java problem but an error at the end of your connection string. Maybe there should be a login/password information here, or anything of the like.

Microsoft error messages are often confusing, so I suggested to verify if ODBC source is really available first.
I have no working example by hand today, but I'll fetch this on Monday.
LS
Reply With Quote
  #5 (permalink)  
Old 11-15-09, 05:18
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
I am almost sure I have not installed JDBC-ODBC Bridge driver or even ODBC driver for java, where found, online to install them...? for Access 2003...
Reply With Quote
  #6 (permalink)  
Old 11-16-09, 05:49
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
Hi...
You should look at:
http://java.sun.com/j2se/1.3/docs/gu...ridge.doc.html
As they say, the JDBC-ODBC bridge driver you try to use is a part of java 2 SDK, so you already have it (somewhere in your development IDE).

Then, you must configure an ODBC data source in your system: Control Panel/System Administration Tools/Data Sources (ODBC).
Add a new source pointing to your Access database file using ODBC Access driver.

HTH
Laurent
Reply With Quote
  #7 (permalink)  
Old 11-16-09, 06:31
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
ODBC Access driver must be installed or and this installed along with Access ? how understand if I have it or not visually in windows ? For sure I only ODBC MySQL installed, well how understand about Access ? I run VISTA HOME PREMIUM ...
Reply With Quote
  #8 (permalink)  
Old 11-16-09, 06:50
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
Quote:
Originally Posted by lse123 View Post
ODBC Access driver must be installed or and this installed along with Access ? how understand if I have it or not visually in windows ?
None of the two. It's a part of your Windows system. Go to the ODBC configuration panel, and you shall find it here in the drivers list (along with many others).
Quote:
Originally Posted by lse123 View Post
For sure I only ODBC MySQL installed, well how understand about Access ? I run VISTA HOME PREMIUM ...
The problem is to declare a data source (DSN) not loading or finding drivers which already are there.
If you don't want to use a system or user DSN, you can try this:
Code:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/temp/thebase.mdb";
String user = "user";
String pass = "pass";
Connection connection = DriverManager.getConnection(url,user,pass);
Of course, you have then to replace "C:/temp/thebase.mdb" with the path to an existing Access file.

Laurent
Reply With Quote
  #9 (permalink)  
Old 11-16-09, 07:01
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
You mean ODBC Access driver is an Additional Installation, so if I do not have, I must install ? If I do not have it, where it can be found ?
Reply With Quote
  #10 (permalink)  
Old 11-16-09, 07:02
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
ODBC Access driver is NOT ONLY for java, correct ?
Reply With Quote
  #11 (permalink)  
Old 11-16-09, 09:19
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
Yeah, it's a standalone thing in the system (a JET engine) which provides ODBC access (without cap). Excel spreadsheets have one too.
You can use it with any software knowing ODBC which is a general way to manage datasources.
IMO, you need not to fetch or install anything (except, maybe, a DSN). There's only something wrong in your connection string (url + credentials).

Laurent
Reply With Quote
  #12 (permalink)  
Old 11-19-09, 03:29
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
problem solved ...(first is wrong since must be space between WINES" + "WHERE...
ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES" + "WHERE ...
ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES " + "WHERE ...

ACCESS ODBC Driver usually ships with office(no need install) ?
I used Success:
Connection conn=DriverManager.getConnection("jdbcdbc:RedWin es");
well the below you refer also is valid, and used when no DSN(or must exist?)??? What is DBQ?

String url= "jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=C:/temp/thebase.mdb";
String user = "user";
String pass = "pass";
Connection connection = DriverManager.getConnection(url,user,pass);
Reply With Quote
  #13 (permalink)  
Old 11-19-09, 04:41
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
Quote:
Originally Posted by lse123 View Post
problem solved ...(first is wrong since must be space between WINES" + "WHERE...
ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES" + "WHERE ...
ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES " + "WHERE ...
I'm happy to hear that. But... you never posted this query !
Quote:
Originally Posted by lse123 View Post
I used Success:
Connection conn=DriverManager.getConnection("jdbcdbc:RedWin es");
well the below you refer also is valid, and used when no DSN(or must exist?)???
I don't think a DSN must exist.

Regards
Laurent
Reply With Quote
  #14 (permalink)  
Old 11-19-09, 05:12
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 130
I have another point: (I use DSN) I add records FROM FILE.txt and other case I add TABLES but this do not seem in Access, neither seem to other database driver java files(listing of records)... well? I add like:

public static void main(String [ ] args) {
String fileName = "";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Driver
Connection conn = DriverManager.getConnection
("jdbcdbc:RedWines");
Statement sttmnt = conn.createStatement( // Scrollable
ResultSet.TYPE_SCROLL_INSENSITIVE, // pointer
ResultSet.CONCUR_READ_ONLY );


if (args.length > 0)
fileName = args[0]; // args[0] from command line
else {
System.out.println("Must supply file name – rerun!");
System.exit(0);
}
// Create a new table. Populate it with records from input file.
sttmnt.executeUpdate("DROP TABLE WINES");
BufferedReader inputFile = new BufferedReader(
new FileReader(fileName + ".txt"));
String recordInput = inputFile.readLine(); // Read 1st rec
String sqlCommand = "CREATE TABLE WINES" +
"(" + recordInput + ")"; // Create SQL command
System.out.println(sqlCommand);
sttmnt.executeUpdate(sqlCommand); // Execute SQL command

while ((recordInput = inputFile.readLine())!= null) // Read
{
sqlCommand = "INSERT INTO WINES " + // Build SQL
"VALUES (" + recordInput + ")"; // statement
System.out.println("SQL statement:" + sqlCommand);
System.out.println("Record Added.");
int result = sttmnt.executeUpdate(sqlCommand); // Execute
} // end of while
Reply With Quote
  #15 (permalink)  
Old 11-19-09, 06:06
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
Quote:
Originally Posted by lse123 View Post
I have another point: (I use DSN) I add records FROM FILE.txt and other case I add TABLES but this do not seem in Access, neither seem to other database driver java files(listing of records)... well? I add like:
Your code looks correct, but I don't understand the sentence: "this do not seem in Access". Does this means it doesn't work in Access ?
If so, you cannot hope I could reply anything without further details.
What did you put in your file ?
What's the result of the execution in Access ?
Did you get any errors ? (I suppose there is a "catch" balancing the "try" and hope it displays something).

BTW, I would *never* put DDL statements in a plain text file.

Laurent
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On