Installing Snowflake JDBC driver - java

I am trying to install Snowflake JDBC driver according to instructions.
I have downloaded and installed Java from here, then downloaded snowflake-jdbc-3.6.9.jar file from here. When I double-click the file, nothing happens. So I opened CMD and tried this:
java -jar snowflake-jdbc-3.6.9.jar
I received *no main manifest attribute, in snowflake-jdbc-3.6.9.jar*.
When I open META-INF\MANIFEST.MF file, I do see:
*Manifest-Version: 1.0*
*Main-Class: net.snowflake.client.jdbc.SnowflakeDriver*
I have gotten this far using suggestions from other StackOverflow topics, and don't know what else to try. I don't know much about Java, I just need to install this driver, so I could connect to Snowflake from a BI tool. I would really appreciate your help.

I presume you got it up and running by now.
But as mentioned by one of the other responders, by copying the .jar file to your computer you have already more or less installed the driver.
Different from OBDC drivers, there is no JDBC manager, which expects that JDBC drivers need always to be installed in a certain directory.
You have to point the used application to this driver to use this driver.
Let's take as an example dBeaver, a popular JDBC Query tool among Snowflaker users. (And available for Windows, Mac and Linux)
Before you can use this driver within dBeaver, dBeaver has to be made aware that this driver does exist and can be used.
So after starting up dBeaver you first point dBeaver to the location where you have put the Snowflake .jar file.
(Let's assume that you don't want to use the preconfigured Snowflake JDBC driver for the sake of usefulness of my answer)
So you select New and select 'create new driver'
Under the windows [Libraries] you can add a file or a folder.
Select [Add File] and point at your JDBC .jar file.
As of then you can use the JDBC driver.
For completeness are here the other details to use a different Snowflake JDBC driver than the provided one in dBeaver:
[Driver Type:] Snowflake
[Class Name:] net.snowflake.client.jdbc.SnowflakeDriver
[URL Template:] this contains the default connectstring format to use this JDBC driver (So how a connectstring should look like to make a successful connection to Snowflake)
[Default Port:] 443 (should have been preset)
The rest should be self explanatory.

Have you tried adding the jar to classpath and then running the following command, Class.forName("provided driver name") in the calling class? Doing this with an IDE like Eclipse or Netbeans should make this process much simpler (particularly adding the jar to your project classpath)

Couple of solutions to the above:
1) Using CLASSPATH:
MacOS/Linux: EXPORT CLASSPATH="Path/to/JDBCjarfile:$CLASSPATH"
Windows: There are a couple of way of setting the CLASSPATH
a) Run the following in CMD:
set CLASSPATH=path1;path2
b) In Search, search for and then select: System (Control Panel)
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the CLASSPATH environment variable and select it. Click Edit. If the CLASSPATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of the CLASSPATH environment variable. Click OK. Close all remaining windows by clicking OK.
Reopen Command prompt window, and run your java code.
Document reference: https://www.java.com/en/download/help/path.xml
To confirm if the CLASSPATH variable is EXPORTED or SET:
1) MacOS/Linux:
$ echo $CLASSPATH
2) Windows:
$ echo %CLASSPATH%

Related

java - No postgresql driver found only when ran from Windows' command prompt [duplicate]

This question already has answers here:
What is a classpath and how do I set it?
(10 answers)
Closed 6 years ago.
I'm using Netbeans 8.1 and maven, the project is as simple as connecting to a postgre DB and run a single query.
When I run the project from Netbeans, the System.out.println message I set tells me that the connection to the db went successful, passing by the message in the below code "PostgreSQL JDBC Driver Registered!".
When the same project is ran in the Windows 7 prompt, like:
java -jar myproject.jar
The
try {
Class.forName("org.postgresql.Driver");
}
catch (ClassNotFoundException e) {
System.out.println("No PostgreSQL JDBC Driver found");
System.exit(0);
}
System.out.println("PostgreSQL JDBC Driver Registered!");
Jumps to the catch{}.
I can't explain why. Is somebody able to help me?
EDIT: If we could please stop marking this as duplicate, that'd be great. It may be argument for the classpath, but I do not want to use classpaths. Another application I am using, a variant of this one, simply run without modification to the classpath and does exactly the same Db connection.
There must be a way to achieve it, may be using the pom.xml or something else that I do not know
EDIT2: I'm quite sure that I edited this before, explaining that I found the way to have the program working without adding classpaths to the Windows command.
the pom.xml was the key to configure the application.
And no, the "duplicate answer" did not help me this time.
The reason it does not work is you forgot to set the classpath in your command. The PostgreSQL driver comes in jar. So you must pass the path of this jar location. Since you are using, the jars are located in ~/.m2/repository.
So go in this directory and search for for the driver, and pass -cp to command line with the driver location as a parameter :
java -cp $LOCATION_POSTGRESQL_DRIVER -jar myproject.jar
On Windows 7, however, it is a little more complicated than that. The problem is that, if you simply run cmd and try to start or stop a service, you will most probably get this error message:
System error 5 has occurred.
Access is denied.
To overcome this, you need to start a "DOS box" as Administrator since, to the best of my knowledge, one cannot run a single command as Administrator inside the command prompt window opened under an account with fewer rights (there are no su and sudo commands in Windows).
One option is to click the "Start" button, type cmd into the "Search programs and files" box and hit Ctrl+Shift+Enter instead of just Enter. This will start a "DOS box" with administrative rights. Now, in this DOS box, you can run one of these commands (replacing the "9.1" with whatever your actual version of PostgreSQL is):
NET START postgresql-9.1 (for the 32-bit version)
NET STOP postgresql-9.1 (for the 32-bit version)
NET START postgresql-x64-9.1 (for the 64-bit version)
NET STOP postgresql-x64-9.1 (for the 64-bit version)
to start and stop PostgreSQL.

Raspbian/Java: Classpath and MySQL, working in Windows and not on Pi

I know this question has been asked/answered several times, but I still couldn't find a solution to this ClassNotFoundException error, because it works on my computer but not on my RasPi (on which I installed OpenJDK7).
My application uses JDBC to access a MySQL database, and that's the main problem. As has been pointed out on lots of websites ([1], [2], [3]), this is, unfortunately, a common problem.
So, I'm using the mysql-connector-java-5.0.8.jar as a driver. My folder structure is something like /src/de/web/project/ I'm calling the main method via java de.web.project.WakeOnLan (which is the main class that starts all other classes etc.) I got the common ClassNotFound exception and therefor added the -cp parameter so I called the project via java -cp .;mysql-connector-java-5.0.8.jar de.web.project.WakeOnLan to add the driver to classpath.
This worked nicely on my Windows computer from command line, but now I want to push this code to my Raspberry Pi and execute it there. As I said, I installed OpenJDK7 there (using apt-get, if this should be important), used SFTP to upload the folder structure and the code to /home/pi/java/ where there is also the ejre1.7.0_10 folder (so the code is now actually in /home/pi/java/de/web/project/).
I now went back to /home/pi/java and entered java -cp .;mysql-connector-java-5.0.8.jar de.web.project.WakeOnLan as I did on my Windows computer, but it refuses to work (I've put the connector in any folder on the way, just in case). When I call this function, I get a long list of hints Java wants to give me which parameters are allowed for java, finally stating: -bash: mysql-connector-java-5.0.8.jar: command not found. I also tried to turn ".;mysql..." around to "mysql...;." which didn't work as well. If I don't include the -cp parameter, my program says "Thread started" and in the next line: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver etc., so the program does indeed start and writes "Thread started" to System.out.
For some reason, it looks like Java on the Pi ignored the second value of the classpath parameter for which I don't see a good reason.
You might just have problem in classpath setting, there is difference for windows and linux
The classpath syntax is OS-dependent. From Wikipedia :
Being closely associated with the file system, the command-line
Classpath syntax depends on the operating system. For example:
on all Unix-like operating systems (such as Linux and Mac OS X), the
directory structure has a Unix syntax, with separate file paths
separated by a colon (":").
on Windows, the directory structure has a Windows syntax, and each
file path must be separated by a semicolon (";").
This does not apply when the Classpath is defined in manifest files,
where each file path must be separated by a space (" "), regardless of
the operating system.

Java settings, classpath and environment variables

I'm not sure if it is best practice but I add MySQL-connector jar to the extensions directory of my Java install directory to I can easily connect to MySQL databases.
I also set environment variables to point to various directories so that I can develop on different machines and only define environment variables locally and code doesn't have to be modified for file paths.
In either case of the above I find that unless I reboot my computer java does not recogise either. What happens during a reboot to Java? Is some config file updates by a java process? Can you update this without having to reboot?
To test this I have created a new environment variable on both Mac (adding to .MacOS/environment.plist), Linux (Ubuntu 12.04) and windows 7 (via control panel). I then used System.getenv("TestVar"); which returns null. Running set from the command line shows it exists though. After a reboot System.getenv("TestVar"); returns the expected value.
Ultimately your goal is to include jar files in CLASSPATH . its up to you how include jars in classpath but this is not good practice to put jars inside extensions directory . While running your program modify CLASSPATH value .
java -cp jar1:jar2:jar3:dir1:. HelloWorld
java -classpathjar1:jar2:jar3:dir1:. HelloWorld
As far as setting environment variables goes the on Ubuntu a log out is required
https://superuser.com/questions/339617/how-to-reload-etc-environment-without-rebooting

java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library

I have two web-applications which need to run on Tomcat 6, MS SQL 2008 and JTDS-1.2.2 as driver.
If I start only one web application everything is working fine, but as soon as I start the second one I get the following error (it does not matter the order):
java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library
Of course, the library ntlmauth.dll is under C:\WINDOWS\system32
It seems that the second application which starts is not able to find the ntlmauth.dll for the single sign on.
I got past this by changing the url from
jdbc:jtds:sqlserver://host_server:1433/Database_name
to
jdbc:jtds:sqlserver://host_server:1433/Database_name;user=XXX;password=YYY
Apparently, "When URL [does] not contains user and password properties, systems uses Windows authentication method, and "SSPI Native library not found" error appears."
This is the solution:
Download the jTDS driver, unzip it, and copy x86\SSO\ntlmauth.dll to jdk\jre\bin.
This should solve your issue.
Edit:
Without the JDK installed the path for me was C:\Program Files\Java\jre7\bin\ntlmauth.dll
jTDS must be able to load the native SPPI library (ntlmauth.dll). Place this DLL anywhere in the system path (defined by the PATH system variable) and you're all set.
If you are trying to run two (or more) Tomcat applications on the same server that both access a SQL Server using the JTDS driver and windows authentication, a very helpful answer courtesy of Chris White is here.
Chris' answer has to do with sqljdbc_auth.dll, but the recommendations are the same for the JTDS driver and ntlmauth.dll:
Put ntlmauth.dll into the tomcat 7.0\bin directory. Actually, I believe you can put ntlmauth.dll into any directory in the system path, or the Java jre\bin directory.
Importantly, don't bundle the JTDS jar in the war file of any Tomcat application using the JTDS driver. Instead, put one copy in the Tomcat\lib directory, where Tomcat will load it and make it available to all apps.
If you are on 64-bit windows but running 32-bit java (the one in program files x86) then you need the 32-bit ntlmauth dll and not the 64 bit one that you might have expected.

About the connectivity to IBM database using JDBC in Java

I have a problem connecting to IBM (universal) database using JDBC. I wrote the code in Notepad using Java and I loaded drivers of IBM database i.e(driver name and connection URl). When I run the code using general compilation (javac code.java and java code) I am getting an error message "cannot find the driver" but I specified the correct driver name for that. Actually I did this program using Eclipse using the same database with same driver name and all and finally I succeeded, but I cant get this without using an IDE. So please help me how to connect without the IDE and how to run it in a command prompt.
You need to include the necessary JAR files on the classpath when you run your program on the command line.
If you're using IBM's DB2 UDB database, the required driver file is db2jcc.jar, and I think db2jcc_license_cisuz.jar and db2jcc_license_cu.jar are necessary for licensing as well. Search for those files, and include them on the classpath when you run your program from the command line.

Categories

Resources