About the connectivity to IBM database using JDBC in Java - 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.

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%

"Could not find or load main class org.apache.derby.tools.ij" on Eclipse when trying to run derby

I am all very new to database systems. I am trying to connect derby to Eclipse by passing in this command
java org.apache.derby.tools.ij
under the external tools configurations in the "Arguments" section. I have set the location to
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/java
and the error is that it "Could not find or load main class org.apache.derby.tools.ij".
I have tried using javac and javadoc but still, have had no success. Also, I have and OS machine.
Ideally, when this is set up properly I can start inserting to the database when I see ij> in the console.
You have to specify a classpath, either using a command line argument or by setting it into the environment, so that the java command knows where to find the main class you want it to run.
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html or run java -help for a short guide of its common arguments.

H2 Database not working on Linux

I'm using Maven on NetBeans to import H2 Database to my project and the following code to init. a simple embedded database:
//...
Class.forName("org.h2.Driver");
//...
connection = DriverManager.getConnection("jdbc:h2:~/MCUsers");
//...
When I run the code on my Windows machine (where I do the programming), it works fine and I can create tables and rows. But when I run the same JAR file on my Linux machine, I get the following error:
Error Code:90020 Message:Database may be already in use: null.
Possible solutions: close all other connection(s); use the server mode
[90020-194] Cause:java.lang.IllegalStateException: The file is locked:
nio:/root/MCUsers.mv.db [1.4.194/7]
The same JAR runs on my Windows machine with no problems.
There are no other Java programs running on my Linux machine.
I already tried to reboot the system - didn't work.
Only The files MCUsers.mv.db & MCUsers.trace.db are created in the root directory after this error occurs.
My Linux machine uses JRE1.8.0_112 to execute the JAR file.
Edit:
Adding "FILE_LOCK=NO;" also didn't work.

How to start the local neo4j server on Windows using PowerShell script?

I have downloaded the zip folder of neo4j community edition version-2.3.1 in order to start connecting the neo4j server through Java code. I want to create graph database for indexing of the data. Followed this link originally.
PROBLEMS
I'm unable to start the neo4j server as the batch file is deprecated and it displays the following message:
Tried using the PowerShell scripts commands also with reference to this link, it just opens the script file. the server is not started with these commands.
Where I am going wrong and what is the right procedure to start the local neo4j server and connect it through Java code to create nodes and relationships of the graph.
The batch file will still work even though it has been deprecated. It appears that the batch file cannot find the Findstr command.
findstr.exe should be in %windir%\system32\
If it is there and you are getting the findstr is not recognized as an internal or external command” error, check that %windir%\system32\ is in your PATH.
Once that works, try the Neo4j.bat file again.
And as Anton mentioned, please explain how the Powershell didn't work and what actions you took.

MSSQL Window authentication issue with Tomcat server

I have web based application and have MSSQL server 2012 and need to access that database using window authentication and using Tomcat 6 and OS Windows
But same functionality work fine (window authentication) with MSSQL server 2008 not MSSQL server 2012. So may i know the reason is there some thing miss in configuration.
i put jtds-1.2.5.jar in apache\lib directory and also put the ntlmauth.dll in C:\Windows\System32 location and also added the system variable "JAVA_OPTS" for the dll location but it does not work. It gives the error message :
2014-10-14 13:35:35,237 ERROR Unable to get database connection: SQL Exception occurred
java.sql.SQLException: Cannot open database "Test" requested by the login. The login failed.
Then i put the dll in jre\bin directory but it does not work please let is any wrong am doing.
Also try put the dll in apache\bin loc still getting the same issue.
But as per the client requirement that want using JTDS api not the Microsoft driver so need solution in JTDS api. Although it work fine MSSQL server 2008 but does not work in MSSQL server 2012.
I follow the link http://www.dekho.com.au/dekho-connecting-to-sql-server-using-windows-authentication/
we had similar problems with JDTS and at some point resorted to using the official JDBC driver from Microsoft. The Microsoft Driver works on Windows, Linux and MacOS and did not require me to put any DLLs or something like this anywhere.
http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx
The only downsides to this driver are (1) it is not open source so you cannot change it in case you need to, and (2) you need to accept a license. However (2) should not be a problem since you are using MSSQL Server anyways.
Finally (I am not sure if this applies to you) the Microsoft driver cannot be used with Maven. So I (on a Mac) use the following bash script to install the driver into my local Maven repository.
#!/bin/bash
mvn install:install-file -Dfile=lib/sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=3.0 -Dpackaging=jar
For the JDBC Connection strings see the following webpage:
http://msdn.microsoft.com/en-us/library/ms378428(v=sql.110).aspx
In your case since you want to do Windows authentication you need to make sure that you add
;integratedSecurity=true;
to the jdbcUrl.

Categories

Resources