Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
    }
}
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
Thank you,i think i got the wrong version but i got new error: java.sql.SQLException: SQLite only supports TYPE_FORWARD_ONLY cursorsException in thread "AWT-EventQueue-0" java.lang.NullPointerException at tes.MainForm.Tampil(MainForm.java:31) at tes.MainForm.<init>(MainForm.java:52) etc.. –  Adamanusia Nov 19 '13 at 8:08
    
@Adamanusia please raise new question for this one. As this one sounds like fixed to me. –  Peter Butkovic Nov 19 '13 at 8:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.