Java Project Error after changing database from MySQL to SQLite

i am learning java i have created simple (CRUD) java program utilizing mysql,its works fine

and i want to try switching to SQLite with the same database(i already converted mysql database to sqlite)

i am using this JDBC driver: https://bitbucket.org/xerial/sqlite-jdbc

But somehow,netbeans cannot complete running my program(despite there are no errors before) i got many new errors on output bar:

java.lang.ClassNotFoundException: org.sqlite.JDBCException in thread "AWT-EventQueue-0" java.lang.NullPointerException
at tes.MainForm.Tampil(MainForm.java:46)
at tes.MainForm.<init>(MainForm.java:85)
at tes.MainForm$4.run(MainForm.java:329)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)`

My DBConnection class

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnection {   
Connection c = null;
Statement script;

public DBConnection(){
    try{
        Class.forName("org.sqlite.JDBC");
 //  Class.forName("com.mysql.jdbc.Driver");
   // c = DriverManager.getConnection("jdbc:ucanaccess://c:/asa.accdb");
 c = DriverManager.getConnection("jdbc:sqlite:C:/titit2.db");
   // c = DriverManager.getConnection("jdbc:mysql://localhost:3306/titit","root","root");
    script = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    System.out.println("Koneksi Sukses");
    }catch(  SQLException | ClassNotFoundException ex){
    System.err.print(ex);
    }
}
}

Inside my mainform class (line 23-46)

    private void Tampil(){
    try{
        int row = tabel.getRowCount();
        for(int i=0;i<row;i++){
            tabeldata.delete(0, row);
        }
        String sql;
        sql = "SELECT * from asu";
            ResultSet rs = c.script.executeQuery(sql);

        while(rs.next()){
            DataPegawai d = new DataPegawai();
            d.setNo(rs.getInt("no"));
            d.setNip(rs.getInt("nip"));
            d.setNama(rs.getString("nama"));
            d.setDivisi(rs.getString("divisi"));
            d.setLevel(rs.getInt("level"));
            tabeldata.add(d);
        }
    }catch(SQLException e){
        System.err.print(e);
    }
}

Answers


ClassNotFoundException is an exception you can get during runtime. See: http://docs.oracle.com/javase/7/docs/api/java/lang/ClassNotFoundException.html where it says the possible cause:

Thrown when an application tries to load in a class through its string name using:

  • The forName method in class Class.
  • The findSystemClass method in class ClassLoader .
  • The loadClass method in class ClassLoader.

So the problem is from my point of view, that you did not add it in netbeans to classpath correctly.

Moreover you should check you used the stable released version of driver. I'd suggest to use: sqlite-jdbc-3.7.2.jar


Need Your Help

Anyone able to help me with this bug in a login form?

php sql database passwords

So, I have a login form which is having a bit of trouble. It keepsechoing Incorrect password, please try again. whenever I try and access the restricted page. I have had a fiddle on myself, but I h...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.