Windows 8.1. - Java - ODBC Driver - NetBeans [duplicate] - java

This question already has answers here:
Removal of JDBC ODBC bridge in java 8
(5 answers)
Closed 7 years ago.
I am trying to connect Java app to MSAccess in NetBeans IDE (pls don't tell me not to use Access, because we are using it in classes, and that's just it for now :)). I didn't have this problem on Windows 7, and I couldn't find answer using Google, so I decided to post this question.
So, it's like this, I have:
Windows 8.1 (64-bit)
Java jdk1.8.0 (32-bit)
NetBeans IDE 8.0, and NetBeans jdk home (from netbeans.conf) is: "C:\Program Files (x86)\Java\jdk1.8.0", so it's using 32-bit jdk.
Code for loading driver:
public void loadDriver() throws RuntimeException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
throw new RuntimeException("Could not load driver!");
}
}
Code for opening connection:
public void openConnection() throws RuntimeException {
try {
connection = DriverManager.getConnection("jdbc:odbc:db");
connection.setAutoCommit(false);
} catch (Exception e) {
throw new RuntimeException("Could not connect!");
}
}
Of course, there's an attribute:
private Connection connection; (and import java.sql.Connection;)
There is a problem at loading driver - it always says "could not load driver". If I have to post more code or change something in what I've posted, please tell me and I will.
I went to: SysWOW64 - odbcad32.exe - Add... - Microsoft Access Driver (*.mdb, *.accdb), and then for Data source name I've put of course "db" (like in my code above) and selected the database (.accdb file) that I will use. And I don't know if it is the Windows 8 issue or I'm forgetting something, but I really have no clue how to make it work.

The JDBC-ODBC Bridge has been removed from Java 8. For an alternative, see the related question here:
Manipulating an Access database from Java without ODBC

Related

Jar not getting executed in other's pc [problem with JDBC external jar/maven dependency, connection not getting established] [duplicate]

This question already has answers here:
SQLException: this driver is not configured for integrated authentication tomcat
(3 answers)
Closed 2 years ago.
I have written a code to connect to a database using JDBC, I am using openJDK11.0.2, 64 bit, and external jar [mssql-jdbc-8.4.0.jre11] (which i added to libraries inside "properties" in eclipse)
I added a maven dependency as well
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre11</version>
</dependency>
So in my code, I am using windows authentication and my code looks like this,
public static void main(String[] args) throws SQLException {
String connString = "jdbc:sqlserver://" + serverName + "\\MSSQLSERVER:1433;" + "databaseName = testUserDb; integratedSecurity = true;";
System.out.print("\nConnection String : " + connString + "\n");
conn = DriverManager.getConnection(connString);
System.out.println("\nConnection Established");
System.out.println("\nSuccess");
}
I exported my code as a runnable jar, and the code is running fine when I am executing my jar using java -jar demoJava.jar
But when I gave my jar to my partner, on his computer (using same version of java) on his I got error, connection is not getting established.
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication
It there a way I can make my code universal, and it will run anywhere (when I am exporting as a runnable jar, the external mssqljdbc jar is present in my JAR) but it is only getting executed in my system.
What am I missing? Something to do with driver dlls? Please suggest.
Just add "mssql-jdbc_auth-8.4.0.x64.dll" to other peoples jdk_version/bin and rerun the process, it will work, I faced same problem. That is how I resolved it.
Make sure to use correct version (64/86)
The very first Google result for this error message leads to documentation at Microsoft :
https://techcommunity.microsoft.com/t5/sql-server/com-microsoft-sqlserver-jdbc-sqlserverexception-this-driver-is/ba-p/383296
which says "This generally indicates that the driver can not find the appropriate sqljdbc_auth.dll in the JVM library path."
There's a fix recommend there for specifying the path to the DLL, assuming that you have it. Of course, that would only work on Windows.
A more universal approach would be to use a pure-java JDBC driver, like the jTDS JDBC Driver.

Error accessing PostgreSQL using Eclipse Windows 10 [duplicate]

This question already has answers here:
Postgres JDBC connection in Eclipse Help
(5 answers)
Closed 4 years ago.
I am in the process of learning Java and PostgreSQL. I am running Windows 10 with JRE 10, my IDE being Eclipse Oxygen 3a. I had written the following code:
import java.sql.Connection;
import java.sql.DriverManager;
public class PostgreSQLJDBC {
public static void main(String args[]) {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/testdb",
"postgres", "123");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
}
It successfully compiles. However, it gives me the following error
java.lang.ClassNotFoundException: org.postgresql.Driver
In following the advice given in Stack Overflow, I have downloaded postgresql-42.2.2.jar and placed within C:\Program Files\Java\jre-10.0.1
I then edited my system variables and added "C:\Program Files\Java\jre-10.0.1" into it. However I still get the same error. Please help
Adding a .jar to your JRE is like forcing a DLL to load into every Windows application you run. There's almost never a good reason to do so.
Add the Postgres driver jar to the project's Java Build Path.
http://help.eclipse.org/oxygen/topic/org.eclipse.jdt.doc.user/reference/ref-properties-build-path.htm?cp=1_4_3_1
Maybe go through the tutorial and learn to use your tools. http://help.eclipse.org/oxygen/topic/org.eclipse.jdt.doc.user/gettingStarted/intro/overview.htm?cp=1_0

Exception on loading JDBC-ODBC driver

I am getting java.lang.ClassNotFoundException on loading sun.jdbc.odbc.JdbcOdbcDriver using Class.forName().
I am using MySQL as Data Source and I have added Data Source Name in ODBC Data Source Administrator (on Windows 8).
Here is the code:
class Connect {
check() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Output:
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
Are you using Java 8? The class is no longer present there (more info). You could install Java 7 if you need to use it.
This happened to me once, and what i did was importing the mysql jdbc library that came with the product when i downloaded it, after that i used the driver as it is explained in the page:
http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html
hope this could help you

Exception: No suitable driver found for jdbc:mysql

I am trying to connect to a mysql database by using this simple code.
import java.sql.*;
public class OdbcAccessConnection_1 {
public static void main(String [] args) {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
// Connect with a url string
con = DriverManager.getConnection("jdbc:mysql://localhost/books","root","1234");
System.out.println("Connection ok.");
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
e.printStackTrace();
}
}
}
All it does is tell me if the connection is working. There is no problem with my database and this code/connection work on netbeans. The StackTrace i am getting is -
the java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/books
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at OdbcAccessConnection_1.main(OdbcAccessConnection_1.java:13)
I am working on 64 bit windows 7 and using 5.1 versions of the Connector/ODBC driver 64 bit. On the ODBC all seems to connect and the test was successful. But when i run the code i get the stack trace above. I am missing something very simple so any input and help would be very much appreciated.
Thank you:)
Go to Run menu in netbeans or whatever IDE you are using
=>Set Project Configuration then Customize.Then choose the Libraries on left dropdown menu
Add your appropriate driver file either jar or folder.
Click OK.
jdbc:mysql://localhost/books is a URL that you use to connect to MySQL directly, using the MySQL JDBC driver. The URL used by the JDBC/ODBC driver is different (see http://docs.oracle.com/javase/1.3/docs/guide/jdbc/getstart/bridge.doc.html).
The usage of this JDBC/ODBC bridge is discouraged, and should only be used to access a database that doesn't provide any JDBC driver. This is not the case of MySQL. Use Connector/J, their JDBC driver. Once you have this driver in your classpath, you can use the URL you're currently using, and remove the JDBC/ODBC driver from your classpath (and its loading from your code).
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/books","root","1234");
This error creeped on me because I forgot to add the Class.forName line. The mysql driver jar was on the classpath but no one implicitly loads the driver class, so the session factory can't find any driver classes loaded. Thus the purpose of this line.
In your case, you're loading the wrong thing. It should be Class.forName("com.mysql.jdbc.Driver") if you intend to use it with a jdbc:mysql:// connection.
best solution bhai logo -:
go to JCreator configure menu then click to options then JDK profiles then double click to whatever the version u r using automatically mention there then click to add archive then go to that path -> C:\Program Files\MySQL\MySQL Tools for 5.0\java\lib\mysql-connector-java-5.0.4-bin.jar press ok.

Connecting to SQLite Database Fails

I am attempting to access my SQLite3 database in a Java Applet. When I run my code to connect to the database I get this error No suitable driver found for a.db, how can I fix it?
Now I am not entirely sure I have actually installed the correct driver...I will tell you what I have done & could you tell me what else I need to do to make Eclipse IDE find the SQLitejdbc driver:
BK info: On windows 7, using Eclipse Helios Java
I have a SQLite3 database created in python & I want to read it in my Java Applet
I have downloaded the file sqlitejdbc-V056.jar from http://www.zentus.com/sqlitejdbc/
Then I copied & pasted the above file to the paths C:\Program Files\Java\jre6\lib & C:\Program Files\Java\jre6\lib\ext
Run the following code in a Java Applet & get an exception thrown with the text: "No suitable driver found for a.db"
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("a.db"); // exception thrown here
Any information would be really helpful. Do I need to import the driver into my Eclipse project?
Try this:-
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:a.db");

Categories

Resources