Popular error - org.sqlite.JDBC - java

package aplikacjajava;
import java.sql.*;
public class main
{
public main( String args[] )
{
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:projekt.db");
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Opened database successfully");
}
}
Error:
java.lang.ClassNotFoundException: org.sqlite.JDBC
I know that I'm missing JDBC driver. How to install it on Fedora?
I don't how to add some "path" and what is this at all. I need something like step-by-step explanation... This is first time when I met with such a problem.

Download the SQLite-jar at http://search.maven.org/remotecontent?filepath=org/xerial/sqlite-jdbc/3.8.10.1/sqlite-jdbc-3.8.10.1.jar
Add the jar file to your class path (open Eclipse project properties, there you'll find the build path)
Run your program.
You usually use Maven, Gradle or manual dependency management when using Java. Linux package managers are very limited in java support.

After I set the classpath from the command prompt, I could use the Database by running java javafile.java, and the database was working fine only from the command prompt.
The Eclipse IDE does not recognize the class. While I tried to add external jar file, the good news was when I defined the classpath as a variable inside the Eclipse IDE, then the issue was solved completely.
I did notice your request and tried to add well-detailed instructions on how to fix that issue.
For also solving this issue, follow the steps below:
Download a sqlite-jdbc-XXX.jar file
in the Eclipse IDE from the left side, right-click on your project and then select properties
on the left menu, choose the Java build path and click Add variable
click Configure variables and then click New
you should name the variable name field as you name it on the Class.forName("org.sqlite.JDBC"); line, that means your variable name is: org.sqlite.JDBC
on the variable path, you should choose your sqlite-jdbc-XXX.jar file
Finally, I got results from the database also in the Eclipse IDE.
‏ ‏
‏ ‏ ‏‏ ‏ ‏

Related

Exported .jar when run on other computers give "No suitable driver found for jdbc"

I made a small and simple program using IntelliJ IDEA to update content on some new columns in a MSSQL database. I downloaded the external library sqljdbc4.jar and added this to Project Settings > Libraries, as well as making sure that the library .jar is added to the output layout. I have confirmed that the sqljdbc4.jar is included to the exported .jar-file by unpacking the file on the Mac I use.
The program runs just fine on my Mac, but when I copy the .jar over to a colleague's computer, or try to run in in Windows on Parallels, we only get a ClassNotFound Exception with a following note that "No suitable driver found for jdbc:sqlserver[server details]"
The code for the job is as following:
//[....]
private final static String SQL_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
public SQLConnector(){
}
public boolean updateDatabase(String[] results, boolean inhouse){
Connection conn;
try{
Class.forName(SQL_DRIVER);
} catch (ClassNotFoundException e){
JOptionPane.showMessageDialog(null, "ERROR: " + e.getMessage(), "Exception type: ClassNotFoundException", JOptionPane.ERROR_MESSAGE);
return false;
}
//[...]
The ClassNotFound-exception is what is triggered. Any ideas? If some additional information is required, please do not hesitate to request it.
EDIT: I have the sqljdbc4.jar saved in /Library/Java/Extensions, and if I remove it from there then the program also fails with the same error on my Mac. Even if I have the .jar-file stored in a /bin/-folder in my project and make sure that this file is the file added as a library. With jdbc-jar removed from Extensions, the program will still run fine when executed from IntelliJ even so.
I figured it out. The problem was in the settings for artifacts. When specifying details to create JAR from modules, I had previously selected "extract to the target JAR", but the correct option seemed to be "copy to the output directory and link via manifest". Doing this gave an error that a manifest already existed, so I had to go manually in and delete the META-INF folder in both "src" and in "out > production > [project name]". Then allow IntelliJ to build the artifact anew. This resulted in the sqljdbc4.jar file being added alongside my own JAR, instead of copying the sqljdbc4.jar file into my own JAR.
I do not know what the major difference between these two options are however....

No suitable driver found for jdbc:mysql://localhost:3306/world [duplicate]

This question already has answers here:
The infamous java.sql.SQLException: No suitable driver found
(21 answers)
Closed 7 years ago.
Using Java, I get this error when attempting to connect to a mysql database:
java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost:3306/mysql at
java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MyTest1.main(MyTest1.java:28)
I'm using the mysql-connector-java-5.1.18-bin.jar driver. It is in my build path. I have restarted MySQL. I've also logged on from the command line with root and no password and it connected fine. I'm not currently seeing a port 3306 in netstat. Previously I was getting a different error (I didn't change the code). The error was "jdbc mysql Access denied for user 'root'#'localhost password NO"
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url, "root", "");
}
catch (Exception e){
e.printStackTrace();
}
In this particular case (assuming that the Class#forName() didn't throw an exception; your code is namely continuing with running instead of throwing the exception), this SQLException means that Driver#acceptsURL() has returned false for any of the loaded drivers.
And indeed, your JDBC URL is wrong:
String url = "'jdbc:mysql://localhost:3306/mysql";
Remove the singlequote:
String url = "jdbc:mysql://localhost:3306/mysql";
See also:
Mini tutorial on MySQL + JDBC connectivity
You have to set classpath for mysql-connector.jar
In eclipse, use the build path
If you are developing any web app, you have to put mysql-connector to the lib folder of WEB-INF Directory of your web-app
When using Netbean, go under project tab and click the dropdown button there to select Libraries folder. Right Click on d Library folder and select 'Add JAR/Folder'. Locate the mysql-connectore-java.*.jar file where u have it on ur system.
This worked for me and I hope it does for u too.
Revert if u encounter any problem
This error happened to me, generally it'll be a problem due to not including the mysql-connector.jar in your eclipse project (or your IDE).
In my case, it was because of a problem on the OS.
I was editing a table in phpmyadmin, and mysql hung, I restarted Ubuntu. I cleaned the project without being successful. This morning, when I've tried the web server, it work perfectly the first time.
At the first reboot, the OS recognized that there was a problem, and after the second one, it was fixed. I hope this will save some time to somebody that "could" have this problem!
A typographical error in the string describing the database driver can also produce the error.
A string specified as:
"jdbc:mysql//localhost:3307/dbname,"usrname","password"
can result in a "no suitable driver found" error. The colon following "mysql" is missing in this example.
The correct driver string would be:
jdbc:mysql://localhost:3307/dbname,"usrname","password"
i had same problem i fix this using if developing jsp, put mysql connetor into WEB-INF->lib folder after puting that in eclipse right click and go build-path -> configure build patha in library tab add external jar file give location where lib folder is
Just telling my resolution: in my case, the libraries and projects weren't being added automatically to the classpath (i don't know why), even clicking at the "add to build path" option. So I went on run -> run configurations -> classpath and added everything I needed through there.
( If your url is correct and still get that error messege )
Do following steps to setup the Classpath in netbeans,
Create a new folder in your project workspace and add the downloaded .jar file(eg:- mysql-connector-java-5.1.35-bin.jar )
Right click your project > properties > Libraries > ADD jar/Folder
Select the jar file in that folder you just make. And click OK.
Now you will see that .jar file will be included under the libraries. Now you will not need to use the line, Class.forName("com.mysql.jdbc.Driver"); also.
If above method did not work, check the mysql-connector version (eg:- 5.1.35) and try a newer or a suitable version for you.

Error in COMM API Installation: nblibraries.properties file doesn't exist

I'm trying to run this sample code which is querying available com ports from here: http://www.java2s.com/Code/Java/Development-Class/QueryingAvailableCOMPorts.htm
// Install the Java Comm API first. if there is no necessary file, say Dll files, the API
// won't work.
import java.util.Enumeration;
import javax.comm.*;
import java.util.Enumeration;
public class ListPorts {
public static void main(String args[]) {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "Parallel";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
}
}
}
I added comm api properly into my project, i can see my comm.jar file under Libraries folder of my project. But when i build the project, netbeans gives me this message:
ant -f C:\Users\Timur\Documents\NetBeansProjects\KEYCON clean jar
C:\Users\Timur\Documents\NetBeansProjects\KEYCON\nbproject\build-impl.xml:63:
Source resource does not exist:
C:\Users\Timur\Desktop\javax.comm\nblibraries.properties BUILD FAILED
(total time: 0 seconds)
And when i try to run project, Netbeans gives this message:
run: Error loading win32com: java.lang.UnsatisfiedLinkError: no
win32com in java.library.path BUILD SUCCESSFUL (total time: 0 seconds)
Should i store my comm.jar file somewhere specifically? It's in my desktop now. Or does the problem occurs because of something else?
Another question of mine which wasn't answered by this community :/
And again i have write answer by my own. so here it is:
but the thing is what i write here is generally the same solution for similar questions on this site or other sites and yet i didn't work out at first 8-9 times.
For the jdk (Java Developnment Kit) to recognize the serial ports on
your machine, it is important to properly place these files in the
right folders on your local machine :
%Java_HOME% = the location of your jdk directory.
To Find your JDK directory, Use the Following steps:
Click on Start
Click on Search
Click on For Files or Folders …
In the Left hand Side, Click on All Files and Folders
Type in jdk* in the textbox under All or part of the file name:
Click Search
Look for yellow icon that looks like a folder
Double Clikc on the folder to open the jdk folder
comm.jar should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext win32com.dll should be placed in:
%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32 javax.comm.properties should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
One of the reason, this issue can occur when you have installed fresh Netbeans and open a project having reference to a custom library.
I had same issue and I resolve by just creating a custome library
Create Library
Select Tools > Libraries to open up the Library Manager.
Click the button Add JAR/Folder and browse to the lib folder within the ImageGear for Java installation directory. Select all *.
Click Add JAR/Folder to accept the JAR files you have selected. Then in the Library Manager, click OK to exit.
it will create the nblibraries.properties file and issue will be resolved. now you have to provide reference .jars only
Note: you may have different problem, but if problem is same like me you can try this method.

Setting up path Connector/J in windows 7

Can anyone please tell me as to how to setup the path for Connector/j using the "mysql-connector-java-5.1.18-bin.jar" in windows 7?
I'm using the below code and it always end up throwing an exception.
(java.lang.ClassNotFoundException : com.mysql.jdbc.driver)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class LoadDriver
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Connection working");
}
catch (Exception ex)
{
System.out.println("Connection Fail");
System.out.println(ex.getMessage());
}
}
}
I tried following the official documentation of connector/j for setting up the path, but could not understand.
I tried adding E:\PROGRAM FILES\JAVA\jdk1.7.0_01\jre\lib\ext\mysql-connector-java-5.1.18-bin.jar in the "path" environment variable, Please correct me.
First, you dont need newInstance on Class.forName("com.mysql.jdbc.Driver")
Second don't copy jars to your JDK folder, there shouldn't ever bee a need to copy them there. The correct thing to do is add the jar to your project as a dependency. If your not using an IDE, then you want to add the jar to java.exe as a --classpath option when you run your code (run "java.exe /?" for more details). If you're using eclipse, you should add the mysql jar to the project by clicking on the project and selecting "properties" and then "Java Build Path" there will be an "Add JARs..." button on the right. Then the IDE will add it to your classpath automatically.

I'm having trouble embedding HSQLDB into a simple Java (Eclipse) project

After reading up on some options (sqlite, derby etc...), I've decided to throw down with HSQLDB. I've downloaded it, read up on it and followed a 'hello world' type intro to it, and am now stuck.
I believe that you have to put the hsqldb.jar file in the src folder, so I did exactly that. Then I made a reference to the package with Eclipse by going into Run -> Run Configurations, then going into the Classpath tab, then clicking User Entries, then add External Jar, and selecting hsqldb.jar.
I get this :
java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
Here's my code :
package mysqlite;
import java.sql.*;
public class myclass {
public static void main(String[] args) {
try {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:db";
String user = "aUser";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}
I understand it's unable to find a class, but I thought that was what the hsqldb.jar provided.
No, you do not have to put it into src folder. src is for source files (*.java). You have to add this jar into your classpath: click on project properties, choose "Java build path", select tab "Libraries" and add the jar here.
The jar can be stored anywhere in your file system. Sometimes people create lib directory under project home and put all 3rd party dependencies there.
Try putting the .jar here:
<YOUR_JAVA_HOME>\jre\lib\ext

Categories

Resources