PATH and CLASSPATH variables in java - java

I have just started with jsp. I have downloaded tomcat server. Now when I tried to connect a db with using jdbc. I failed to connect it with MySQL and PostgreSQL. The reasons are:
My java's path is set in PATH variable as C:\Program Files\Java\jdk1.8.0_40\bin
Now for setting path for db (MySQL or PostgreSQL), I am using CLASSPATH variable as E:\XX\XX-XX.jar;
The problem is that when I set classpath my JAVA(not jsp) programs stopped working with an error: Unable to load the class.
and I am also not able to connect yet with any db. Can someone please guide me?
P.S. I am using windows 8.1 and I am not using any IDE.

Could you try adding current directory indicator which is .. Make classpath like E:\XX\XX-XX.jar;.

Related

Installing Snowflake JDBC driver

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%

How to configure Apache Tomcat on a Windows 8.1 installation?

I'm trying to install a 64bit Apache Tomcat distribution on a Windows 8.1 machine but the way in which I have set the environment variables seems to be incorrect.
The steps I have gone through in setting up are as follows:
Copy/Paste apache-tomcat-7.0.57 folder into Program Files (x86)
Set environment variables in the environment variables gui.
Set TOMCAT_HOME to the location of the Tomcat folder: C:\Program Files (x86)\apache-tomcat-7.0.57
Set CATALINA_HOME to the location of the Tomcat folder also: C:\Program Files (x86)\apache-tomcat-7.0.57
But when I execute %TOMCAT_HOME%\bin\startup to check it has been installed correctly I get the following error in my CMD:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
I found a related question on SO and it gave me the following fix but that http://goo.gl/aNmxGM but that threw another error below:
files was unexpected at this time
I gathered from this that there is a problem in the way I'm setting up the environment variables or possibly the placement of the Tomcat folder. Does anyone have any advice on a fix for this issue?
I think that what you really need is to put it between "" as your path contains space
"%TOMCAT_HOME%\bin\startup"
or
"%TOMCAT_HOME%"\bin\startup
I hope this could help!
Use
"%CATALINA_HOME%"\bin\startup
in the command prompt if you have set the environment variables correctly. I have tried it and it has worked well.

how do I call sqljdbc_auth.dll

I'm using eclipse and want to make an sql database connection I put the sqljdbc_auth.dll in the buildpath
I'm getting this error message
Dec 18, 2013 10:45:54 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
This driver is not configured for integrated authentication. ClientConnectionId:7a06f...
What am I doing wrong here?
The DLL file has to be present in one of the locations of your PATH environment var.
It may already help to copy the file to the folder windows\system32 or the bin folder of your JRE/JDK. Restart Eclipse and try again.
If this doesn't work you can also specify the parameter java.library.path in your Eclipse Run Configuration like this:
-Djava.library.path=C:\bla\path\where\the\dll\is
Alternativly you can follow this answer which describes in detail how to setup the parameter for a complete project.
See also:
Creating a Java application launch configuration
I solved the problem.
-Djava.library.path=C:\bla\path\where\the\dll\is
just needed quotes around it like this
"-Djava.library.path=C:\Program Files (x86)\jdbc\sqljdbc_4.0\enu\auth\x86"
If the JDBC is still using 32 bit sqljdbc_auth.dll, it could be because the PATH variable has found 64 bit dll before it gets to the newly added PATH environment variable. Add location of the 64 bit sqljdbc_auth.dll in the very beginning of the PATH system variable. In my case it was
C:\nilster\JDBC\sqlserver-sqljdbc_4.2\enu\auth\x64
This helped me get around to the issue.

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