vendredi 18 décembre 2015

java.sql.SQLException: statement is not executing , Help, how can i fix this

im new to using database and sqlite precisely, trying to create a simple sqlite databse program that could create a database, a table, insert and retrieve data , how can i fix this? i keep getting the exception.

java.sql.SQLException: statement is not executing

here is my code

package databaseproj;

import java.sql.*;

public class main {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
    String sDriverName = "org.sqlite.JDBC";
    Class.forName(sDriverName);
    String dbURL= "jdbc:sqlite:hello.db";



Connection conn= DriverManager.getConnection(dbURL);
Statement st= conn.createStatement();

String createtable="CREATE TABLE contacts(name text, number numeric, email text)";
System.out.println("Table created successfully");
String insertcontacts="INSERT INTO contacts(name, number, email) VALUES('nduka',08166459353,'ndukaude')";




st.executeUpdate(createtable);
    st.executeUpdate(insertcontacts);
    System.out.println("Insert complete");


    ResultSet rs= st.getResultSet(); 



    conn.setAutoCommit(false);
    while ( rs.next() ){
        String name= rs.getString("name");
        int num=rs.getInt("number");
        String email=rs.getString("email");

        System.out.println("NAME: "+name);
        System.out.println("NUMBER: "+ num);
        System.out.println("EMAIL: "+email);


     }

    conn.commit();
    conn=null;
    System.out.println("connection emptied");
    rs.close();

    st.close();

    conn.close();
    System.out.println("connection closed");
    }

    catch ( Exception e ) {
          System.err.println( e.getClass().getName() + ": " + e.getMessage() );
          System.exit(0);
        }
}

}

Aucun commentaire:

Enregistrer un commentaire