I have a program that, when compiled using the 32 bit JVM works fine, but has issues if I try to use the 64 bit JVM. The message I'm getting is: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
I'm trying to connect to Excel and SQL Server databases using code like the following:
String file = directory + "/fileName.xlsm";
String connectStr= "jdbc:odbc:DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + file + ";READONLY=false";
try {
Class.forName(getDriver());
gConnection = DriverManager.getConnection(connectStr);
//do stuff with connection
}
When I tried to check the Driver Manager it didn't seem to have 64 bit version of the drivers. Any way to fix this easily and be able to connect using 64-bit drivers without manually changing settings on the computer (as this program will be distributed across multiple computers and I don't want to have to download a driver separately for ever computer that wants to run it)? Also, is it any more efficient to connect using 64-bit drivers, or are 32-bit ones just as good/fast (I do have very large data sets, so small differences would make a difference)?
64-bit applications cannot use 32-bit ODBC drivers, and vice versa, and that is why you are getting that error message. You can verify what ODBC drivers are available by running the 32-bit (C:\Windows\SysWow64\odbcad32.exe) and 64-bit (C:\Windows\System32\odbcad32.exe) ODBC Data Source administrator (Drivers tab) respectively - on a 64-bit system of course. The naming is confusing at first.
An application I worked with had a similar problem - the Access/Excel ODBC driver was 32-bit-only, meaning when run in 64-bit our application could not handle opening Excel or Access database files. We eventually switched to using the Apache POI library which is a Java library that can read/write Excel and other Office documents directly. You may want to consider giving that a try, though switching would involve some amount of work.
At the time, Office 2010 wasn't out yet. I didn't realize they created a 64-bit ODBC driver in Office 2010 and will have to see if that is a legitimate option now... even if it is I don't like relying on ODBC in a Java application.
Related
I have a Java program that uses MYSQL for the database. Every time I want to run the program I must ensure that the MySQL server is running so that JDBC can connect to my database. How can I package my program with a JDBC driver and a copy of MySQL so that it runs in other computers without having to expect the user to install and manually start MySQL separately? I wish to achieve this so that my program will be a portable program with everything correctly and automatically installed by my Java program. Thanks
It may be funny answer but as smart as question. Run Ubuntu from your pendrive. Connect external hdd/ssd. Use dd command to create image of your drive. Than swap your hdd and burn your *.img file to other drive. Then take copied drive to other computer and insert your drive. Than boot. Simpler solution is to use SQLite insted of MySQL.
I'm developing a JSP project with NetBeans on a GlassFish server. The project uses a MS Access file as database. Where do I need to put the MDB file so JSP class can find it at runtime ?
My code
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
location = loc.getAbsolutePath().substring(0, loc.getAbsolutePath().length() - 2);
String filename = location + "\\myDB.mdb";
System.out.print(filename);
String database;
database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database += filename.trim() + ";DriverID=22;READONLY=true}";
c = (DBM) DriverManager.getConnection(database, "", "");
You should need to setup DSN which get connection. See below steps;
Open Windows' ODBC Data Source Administrator as follows:choose Start > Settings > Control Panel > Administrative Tools > Data Sources.
In the ODBC Data Source Administrator dialog box, click the System
DSN tab.
Click Add to add a new DSN to the list.
Scroll down and select the Microsoft Access (.MDB) driver.
Type in the name "yourDataSourceName" (no quotes, but leave the cases the same)
for the Data Source Name
Click CREATE and select a file to save the database to (I chose
"d:\java\test.mdb") - this creates a new blank MS Access
database.
Click "ok" all the way out.
It doesn't really matter where you put the MDB file on the machine. The important part is that Java requires JDBC, the Java world equivalent to ODBC. (not exactly equivalent but you get me drift). But MS Access doesn't support JDBC, only ODBC. You need to set up ODBC as Sai said. Sun a long time ago created the JDBC-ODBC bridge as a bridge until all DBs created JDBC drivers (but not everyone did... like Access). It was meant to go away a long time ago but it is still here and you need to use it and configure it. There are a lot of examples on how to do this if you google "jdbc odbc bridge" but here is a link to this site to start:
JDBC with ms-access?
But really, it is better for you to look this up. There are a lot of top quality sites that will show you. Look for a tutorial on Oracle first, then elsewhere. Stay away from India Rose or whatever it is called. It is the how not to do things.
I would suggest not using MS Access. Is there any reason that you are using MS Access other than familiarity? You would be better served to use a database that has native jdbc drivers. There are a lot of good quality databases having readily available JDBC drivers which are certainly much better quality and more stable than MS Access.
If you want something that is easy to start and use right out of the box, and has free query and database maintenance tools try MySQL. Just make sure you set it up to use the "InnoDB" option. That makes it behave as an 'acid' compliant database.
My preference is PostgreSQL, but it can be a little daunting at first to set up if you haven't used it before, and has no GUI tools built from the core team (it has some built from associate projects but nowhere near the number that is built is provided by MySQL). It has some configuration that needs to be done in order to allow TCP/IP connections, as well as some security configuration on how to allow users to connect. MySQL makes this less painful to the new user. In fact I think it is every bit as easy to use as MS Access. (FWIW I use Postgres because I think the DB engine is a better quality with more horsepower for bigger projects... like an open source Oracle).
There are other free ones out there but MySQL is likely one that you can use easily if you are moving from MS Access.
How can I pack a Java application and MySQL installation files in a single exe file? Can I install the MySQL files automatically in background (or without any inputs from user)? This is just to simplify the installation procedure.
Java is cross platform, MySQL isn't, so you'd have to create various installers for multiple platforms with different MySQL binaries. If you want to include MySQL source code for non Windows systems, then that's another story... so I assume you want just an installation for Windows.
First of all, get an installation software that you'll feel comfortable with. There is a nice list of free and non free installers on Wikipedia.
Second thing, you can do a silent MySQL installation. How it's done is explained here.
But note that doing a silent MySQL installation without user's permission doesn't sound too good to me, since MySQL isn't exactly lightweight software and you might mess up something if a user already has MySQL somewhere installed.
So, by doing this, you have to be extra careful to check if port 3306 is already up and running (default MySQL port), and other sanity checks to see if there's a possibility of another instance lurking in the background.
It would be better if you at least informed your user that MySQL will be installed. Think about these details, because they might be dealbreakers so some of your users.
Use Java Web Start to launch the application.
JWS offers an ExtensionInstallerService that can be used for installing MySQL. Here is a small demo. of the ExtensionInstallerService.
I made a little Java application which writes stuff to an Access database.
When I run it in Eclipse, it works just fine, but when i build it using Maven and run it, it fails.
As soon as I try to access the database it gives me the following error:
[Microsoft][ODBC Manager] Data source
name not found and no default driver
specified
I know this is a common error but there are so many vague solutions out there I'm too confused to get it fixed.
I have no User DSN's or System DSN's whatsoever, I also don't have a running SQL server as far as I know.
I have no clue as to what to do next.
Wondering if this could be a bitness issue (assuming the machine is 64bit)?
I suspect that this is more about which Java Runtime Environment) is being used to execute the built application rather than what is used to actually build it...
Microsoft only has a 32bit ODBC driver for Access - so, unless the Java application is being run in a 32bit JRE then I suspect there will be no way it can interface with the 32bit native C portion of the Bridge that, in turn, will load the 32bit ODBC Driver.
Just a thought...
You probably use connect string with relative .mdb filename. You can use full filename:
jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\Nwind.mdb
I've run into a peculiar problem where a hql query is working as expected on Windows but does not on Linux.
Here is the query:
select distinct resource from Resource resource , ResourceOrganization ro
where (resource.active=true) and (resource.published=true) and
((resource.resourcePublic=true) or ((ro.resource.id=resource.id and
ro.organization.id=2) and ((ro.resource.id=resource.id and ro.forever=true) or
(ro.resource.id=resource.id and current_date between ro.startDate and ro.endDate))))
Explanation: I'm fetching resources from database where they are active, published and either public or shared with an organization such that the sharing is either forever or between 2 dates.
I have the same data in both the databases (exported from Linux and imported in Windows).
On windows I get
Result size = 275
and in Linux I get
Result size = 0
I've looked at the data in Linux and I see that I should get non-zero result size.
Windows has Java 1.5 whereas Linux has Java 1.6
Any suggestions on where I should look to address this problem?
Thanks!
In a SQL command-line tool, enter the SQL one phrase at a time and see when the Linux version goes awry. For best results, do the same thing on Windows.
Make sure the SQL generated is the same on windows and linux.
and you're sure they are referring to exactly the same database, and using the same login? (edit - I re-read and saw I have the same data - Are You Suuuuuure?)
and finally, I see this: and ro.organization.id=2 Are you sure the ID is 2 on both systems? You could get lit up by the sequence numbers/autokey IDs being different.