Italian SQLITE (errore tabella non trovata)

ivanomonti

Expert
Licensed User
Longtime User
ma perchè di da errore di tabella quando esste tale tabella


SUB:
Public Sub login(nome As String, password As String) As String
    
    Dim SQLite1 As SQL
    
    If File.Exists(File.DirApp, "data.db") = False Then
        Return "File non trovato"
    End If
    
    SQLite1.InitializeSQLite(File.DirApp, "data.db", False)
    
    Dim RowCount As Int = 0
    Dim cs As ResultSet
    Dim query As String
    
    query = "SELECT * FROM utente WHERE nome = '" & nome & "' AND password = '" & password & "';"
    
    cs = SQLite1.ExecQuery(query)

    Do While cs.NextRow
        If cs.GetString("nome") = "" Then
            If cs.GetString("password") = "" Then
                RowCount = RowCount+1
                Return "Ben ritornato " & cs.GetString("nome")
            End If
        End If
    Loop
    
    If RowCount = 0 Then
        Return "Utente sconosciuto"
    End If
    
End Sub


codice errore:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Error occurred on line: 33 (SqliteData)
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: utente)
    at org.sqlite.DB.newSQLException(DB.java:383)
    at org.sqlite.DB.newSQLException(DB.java:387)
    at org.sqlite.DB.throwex(DB.java:374)
    at org.sqlite.NativeDB.prepare(Native Method)
    at org.sqlite.DB.prepare(DB.java:123)
    at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
    at org.sqlite.Conn.prepareStatement(Conn.java:404)
    at org.sqlite.Conn.prepareStatement(Conn.java:399)
    at org.sqlite.Conn.prepareStatement(Conn.java:383)
    at anywheresoftware.b4j.objects.SQL.ExecQuery2(SQL.java:365)
    at anywheresoftware.b4j.objects.SQL.ExecQuery(SQL.java:353)
    at b4j.example.sqlitedata._login(sqlitedata.java:111)
    at b4j.example.b4xmainpage._button_login_click(b4xmainpage.java:76)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA$1.run(BA.java:236)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:832)
 

Attachments

  • data.zip
    1.2 KB · Views: 62
  • Cattura.JPG
    Cattura.JPG
    37.8 KB · Views: 43

LucaMs

Expert
Licensed User
Longtime User
Che ci facciamo col db, visto che l'errore sarà nel sorgente del progetto?

La prova che ho fatto ed allego funziona (a parte che è sbagliato il codice di "bentornato" che hai pubblicato").

Direi che sia molto probabile che il file db non si trovi nella File.DirApp, nel tuo caso.
 

Attachments

  • IvanoMontiTest.zip
    11.4 KB · Views: 53

ivanomonti

Expert
Licensed User
Longtime User
Che ci facciamo col db, visto che l'errore sarà nel sorgente del progetto?

La prova che ho fatto ed allego funziona (a parte che è sbagliato il codice di "bentornato" che hai pubblicato").

Direi che sia molto probabile che il file db non si trovi nella File.DirApp, nel tuo caso.

ciao e grazie @LucaMs, come al solito a me da errore, cosa bella che nel tuo esempio va benissimo, copiato e incollato il uo codice nel mio progetto e genera lo stesso errore;

se non esistesse il file data.db avrei errore:
  If File.Exists(File.DirApp, "data.db") = False Then
        Return "File non trovato"
  End If

idem avrei errore se data.db non esistesse:
SQLite1.InitializeSQLite(File.DirApp, "data.db", False)

qui si scatena l'errore:
cs = SQLite1.ExecQuery(query)


lista errori:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Error occurred on line: 33 (SqliteData)
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: utente)
    at org.sqlite.DB.newSQLException(DB.java:383)
    at org.sqlite.DB.newSQLException(DB.java:387)
    at org.sqlite.DB.throwex(DB.java:374)
    at org.sqlite.NativeDB.prepare(Native Method)
    at org.sqlite.DB.prepare(DB.java:123)
    at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
    at org.sqlite.Conn.prepareStatement(Conn.java:404)
    at org.sqlite.Conn.prepareStatement(Conn.java:399)
    at org.sqlite.Conn.prepareStatement(Conn.java:383)
    at anywheresoftware.b4j.objects.SQL.ExecQuery2(SQL.java:365)
    at anywheresoftware.b4j.objects.SQL.ExecQuery(SQL.java:353)
    at b4j.example.sqlitedata._login(sqlitedata.java:111)
    at b4j.example.b4xmainpage._button_login_click(b4xmainpage.java:76)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA$1.run(BA.java:236)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:832)
 

Attachments

  • Cattura.JPG
    Cattura.JPG
    37.6 KB · Views: 42

drgottjr

Expert
Licensed User
Longtime User
e se data.db e' vuoto? esiste il file, si', ma senza tabelle... perche', non lo so da qui. mi domando.
 

Sagenut

Expert
Licensed User
Longtime User
Ho provato l'esempio di @LucaMs e funziona.
 

LucaMs

Expert
Licensed User
Longtime User
le tabelle ci sono eccome
Quel tool che stai usando, guarda caso mostra due DB che hanno lo stesso nome, data e data(1) che staranno sicuramente in due cartelle diverse.

Tanto per iniziare, cambia nome al DB, perché "data" non mi sembra adeguato, sia perché generico, sia perché potrebbero esserci problemi con sw vari, come forse anche col driver jdbc.

Poi, per assicurarti di stare usando il db file giusto, metti un Log(File.DirApp), subito dopo l'inizializzazione.
 
Top