Unable to open Clearcase raima database. - java

I am trying to read raima database of Clearcase. The db directory is copied from the vob storage and renamd to vob_db. The location where the vob_db is present, there exists the VOB_DB.java file and dependent dlls and jar file. In fact they were copied from below zip file that contains sample program
[http://raima.com/wp-content/uploads/helloWorldSamples/HelloWorld_JDBC_win64.zip][1]
Below java code ( VOB_DB.java ) is written just to open an close database.
import java.sql.*;
public class VOB_DB {
public static void main (String[] args) throws SQLException {
Connection Conn = DriverManager.getConnection ("jdbc:raima:rdm://local");
Statement Stmt = Conn.createStatement ();
Stmt.execute ("OPEN DATABASE vob_db");
Stmt.close ();
Conn.close ();
}
}
The above code compiles successfully. But when I run it throws below message.
Error: Could not find or load main class JAVA_DB
I am really not sure what wrong is with the program or is there anything missing in it or any dependancy is not set.

I am not going to tell you what to do but directly accessing a ClearCase Raima database is asking for serious trouble. Not something you want to do if your company's intellectual property is stored there.
There are APIs and command line options available for almost anything you would want to do with ClearCase.
Also, the Raima database used for ClearCase is not 100% off-the-shelf. There are a number of additional features which are not documented.

Related

Unable to load suitable drive from java 18 on linux 24.02.1 wsl with mysql version 8.0.31 [duplicate]

This question already has answers here:
Connect Java to a MySQL database
(14 answers)
What is a classpath and how do I set it?
(10 answers)
Closed last month.
I get the following error when trying to execute a Java program with SQL code:
java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost/opiejbc1
I have installed the driver mysql-connector-j-8.0.31.jar in /usr/share/java
I have called the class with java -cp ./:/usr/share/java TestApplication
and with CLASSPATH=./:/usr/share/java set.
My Java code is as follows:
import java.sql.*;
public class TestApplication {
static final String DB_URL = "jdbc:mysql://localhost/opiejbc1";
static final String USER = "opiejbc1";
static final String QUERY = "SELECT * FROM Test1";
public static void main(String[] args) {
// Open a connection
try(Connection conn = DriverManager.getConnection(DB_URL, USER, "");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(QUERY);) {
// Extract data from result set
while (rs.next()) {
// Retrieve by column name
System.out.print("Name: " + rs.getInt("Name"));
System.out.print(", Phone: " + rs.getInt("Phone"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
I have tried inserting Class.forName("com.mysql.cj.jdbc.Driver"); immediately after the try statement, but then I get the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token(s), misplaced construct(s)
at TestApplication.main(TestApplication.java:10)
What am I doing wrong?
I have tried all the recommended solutions as far as I know, but I still get those errors.
As noted by #g00se, the real problem is that the JAR file for the Connector/J driver is not on your runtime classpath. So the java runtime cannot find it.
Solution: put the JAR file on the classpath.
Notes:
If you use a -cp option, the CLASSPATH environment variable is ignored.
If you put a directory on the classpath, you are NOT telling the java to put JAR files (in that directory) on the classpath.
If you wanted to put all JAR files in (say) "/usr/share/java" on the classpath, you could use a wildcard entry; e.g. -cp .:/usr/share/java/*.jar. Note that the *.jar is not shell globbing. It needs to be processed by the java command. (In some cases you may need to escape it to prevent globbing.)
You should (IMO) take the time to read the Oracle documentation on how the classpath works.
Adding a Class.forName call is NOT recommended (except by people who don't understand the problem). If the drivers are on the classpath then DriverManager will find them. And if they are not on the classpath, then using Class.forName is going to fail.
But the reason that you got a compilation error was that you were inserting it at the wrong place:
try ( // HERE is the wrong place
Connection conn = DriverManager.getConnection(DB_URL, USER, "");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(QUERY);) {
The try with resources syntax only allows variable declarations with initializers in that context. A Class.forName call is not such a thing.
I haven't checked, but I think that inserting
Class dummy = Class.forName("com.mysql.cj.jdbc.Driver");
at // HERE in the above would make the compiler happier. But DON'T. It is unnecessary. It won't help. See above for the correct solution.

Java-How Do I Rerefrence Sqlite Database in the Same Folder With My Project Files?

am working on a certain java Management System where am using sqlite as my primary database. Am using netbeans gui builder to work on my project. I have googled and stack overflowed how to reference sqlite database in the same dir with my project files without including full path like c://filepath but nothing promising yet. I don't want to include the full path to my database, I want to use sqlite file from the project files so that everything will work smoothly even after distributing my project...
My Connection Class currently Looks like this;
import java.sql.Connection;
import java.sql.DriverManager;
public class Connect {
private static Connection con = null;
public static Connection connecting(){
try{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:programming.sqlite");
JOptionPane.showMessageDialog(null, "Working", null, JOptionPane.INFORMATION_MESSAGE);
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
}
return con;
}
}
However that's seems not to work.. Remember Connection class and database are saved in the same dir...
Please note am avoiding absolute path like c://users/programming.sqlite
Anything to help please???
I think it must work as you shown, but, you can load programming.sqlite as a java.io.File and then put absolute path into jdbc url connection. I mean this:
File temp = new File("programming.sqlite");
String connection = "jdbc:sqlite:" + temp.getAbsolutePath().replace("\\","\\\\");
con = DriverManager.getConnection(connection);
...
If this code doesn't work for you, then your problem must be with programming.sqlite location, because in this case it is not on the same home dir of your java programm.

SQLite Exception Path does not exist

I am trying to connect an already existing SQLite database to my java project, as a temporary solution for testing a simple log-in dialog. Here is my connector class:
import java.sql.*;
import javax.swing.*;
public class SQLite_login_connector {
//Initializes global connection variable (unused until now!)
Connection conn_log = null;
public static Connection logindb_connection(){
//Simple try catch block that prints error trace log in a JOptionPane if runtime error occurs.
try{
Class.forName("org.sqlite.JDBC");
Connection conn_log = DriverManager.getConnection("jdbc:sqlite:/SQLite/ISRSMS_Login.sqlite");
JOptionPane.showMessageDialog(null, "Connection Successful!");
return conn_log;
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
My SQLite database is located in a folder within my project folder:
When I try running my connector class, it throws the following exception:
For me it looks as if it assumes that the folder which contains my database is located on my F: drive, as opposed to my root project in my local repository. I have tried putting the database into my src folder, as well as into a new resource folder all-together. Every time it throws the same exception. Why does it do that?
As you have metntioned / in yor connection string it is pointing to the root directory of your drive
Remove the / in your connection string Do as follows
DriverManager.getConnection("jdbc:sqlite:SQLite/ISRSMS_Login.sqlite")
For your convenience please follow the naming convention of java language
http://www.oracle.com/technetwork/java/codeconventions-135099.html
Why is your URL .sqllite? I would expect .db - like here
jdbc:sqlite:C:/mydir/mydb.db

Cannot connect to database Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I am having errors with connecting to a MS Access Database (CDCollection.accdb) from Java. The IDE we are using is Netbeans. I have done research on possible solutions as to the error, but due to being inexperienced in the topic, I am not too sure how to solve it. The rest of my class are having the same problem and the teacher does no know how to solve the problem either.
My class is now in the final chapter, Learning Unit 10: Accessing a Database from a Java program, of Funworks's exploring IT: Java Programming. Grade 11.
I would post links to the three sources I have found most useful, but Stack Overflow says I need to have 10 reputation points to post more than 2 links. I have searched both Stack Overflow and the web to find the solution to this error, but those were more advanced than where I currently am.
Edit: Here are the links, thanks to those who upvoted me. The solution they suggest makes sense, but does not seem to work...
http://community.microfocus.com/borland/managetrack/starteam/w/knowledge_base/16933.error-java-sql-sqlexception-microsoft-odbc-driver-manager-data-source-name-not-found-and-no-default-driver-specified.aspx
http://www.coderanch.com/t/440574/JDBC/databases/java-sql-SQLException-ODBC-Driver
http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from-Java
From what I understand, it is due to the school computers and my laptop all being 64-bit and ODBC (Open DataBase Connectivity) being 32-bit. My teacher does not know how to solve this problem, as it is her first time encountering it. When the grade 11s of last year reached this section of the book, the school computers were still 32-bit.
According to what I've read, I need to go to the OBDC Data Source Administrator and, under the System DSN tab, add "Microsoft Access Driver (*.mdb, *.accdb)". I noted that it was already there under the User DSN tab.
Find the OBDC Data Source Administrator at C:\Windows\SysWOW64\odbcad32.exe or Control Panel\System and Security\Administrative Tools\Data Sources (ODBC). The first is preferable, as it seems to have more Drivers available even though the Control Panel shortcut targets the same executable file.
However, I still get the same error once I have added the driver.
Here is my code:
The DB class
package cd;
import java.sql.*;
public class DB
{
private static final String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ={CDCollection.accdb}";
private Connection connection;
private PreparedStatement statement;
private ResultSet resultSet;
public DB()
{
try
{
Class.forName(driver);
System.out.println("Driver successfully loaded");
}
catch (ClassNotFoundException c)
{
System.out.println("Unable to load driver");
System.out.println(c);
}
try
{
connection = DriverManager.getConnection(url);
System.out.println("Connection successful");
}
catch (SQLException e)
{
System.out.println("Unable to connect");
System.out.println(e);
}
}
}
And the UseDB class:
package cd;
import java.sql.*;
public class UseDB
{
static DB db = new DB();
public static void main(String[] args)
{
}
}
For the
DBQ={CDCollection.accdb}
I have tried the full path to the file (C:\Users\\Documents\IT\Java\Databases\CD\CDCollection.accdb), using the double backslash due to the first marking an escape character. I have also tried with forward slashes (/) and I have tried without a path, as it is in the code, and placing the database in the \CD (the project folder), \CD\src (the source folder), \CD\src\cd (the package folder).
Yet, despite this, I and my classmates still get the same output every single we run the program:
run:
Driver successfully loaded
Unable to connect
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
BUILD SUCCESSFUL (total time: 0 seconds)
Could I please have help? Keep in mind that my class has only just started this module today; we have only been doing Access and SQL for 1 month and have been doing Java for a year and a half.
Thank you!
I would suggest you adding a SYSTEM DATASOURCE at ODBC configuration panel. Let's suppose you name it cdcollection. Then your url variable just needs to be:
private static final String url = "jdbc:odbc:cdcollection";
Here's a a nice STEP BY STEP article on how to do just that.
Welcome to StackOverflow.

Java connectivity with PostgreSQL

Can someone please tell me how to connect java file to postgresql database (if possible with code n explanation)
Google is a good start
http://jdbc.postgresql.org/
Here is an example test.java
import java.sql.*;
class test
{
public static void main(String[] args) {
String hostname="", dbname="", username="", password="";
try {
int argno = 0;
hostname = args[argno++];
dbname = args[argno++];
username = args[argno++];
password = args[argno++];
} catch (Exception ex) {
System.err.println("Usage: java -cp driver.jar:. test [hostname] [dbname] [username] [password]");
System.exit(1);
}
try {
Class.forName("org.postgresql.Driver");
Connection connection =
DriverManager.getConnection(
"jdbc:postgresql://"+hostname+"/"+dbname,
username,
password
);
ResultSet rs = connection.createStatement().executeQuery(
"select version() as version"
);
while ( rs.next() ) {
System.out.println(rs.getString("version"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Download a current driver from JDBC download page, compile this and run like this on Unices:
java -cp [driver_file_name].jar:. test [hostname] [dbname] [username] [password]
On Windows:
java -cp [driver_file_name].jar;. test [hostname] [dbname] [username] [password]
Just wanted to expound on Tometzky's answer for other beginners using the Netbeans IDE in UNIX like me.
I want the driver to be recognized as a library in the IDE. If you go to Tools->Libraries, you will see the current list. Hit "New Library" and type "PostgreSQL JDBC Driver" or whatever name you want to give it. Then in the Classpath tab, hit "Add JAR/Folder" and point to where you've saved your downloaded driver. I'm not sure if there is a "correct" place to store it, I think it rather depends on how you back up your system and if multiple users share it. Somewhere in your home directory is fine.
After that, make a new project of type "Java Application" and paste Tometzky's code into main. In your project tree, right click on Libraries and add the JDBC driver directly to the project. Now you don't have to worry about specifying the driver on the command line.
Build your project and head over to its "dist" folder. Now you can run it with the command
java -jar myprojectname.jar 127.0.0.1 [dbname] [user] [pw]
That of course assumes you are connect to the database server on your own machine. [user] and [pw] refer to your PostgreSQL username and pw.
Also, when you download the documentation it comes as a bunch of html files. Save them somewhere and point your browser to the index.html file (in Firefox it is File-->Open File).

Categories