Italian SQLITE (errore tabella non trovata)

ivanomonti

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


Code: Copy
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


Code: Copy
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
    data.zip
    1.2 KB · Views: 434
  • Cattura.JPG
    Cattura.JPG
    37.8 KB · Views: 496
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;

Code: Copy
  If File.Exists(File.DirApp, "data.db") = False Then
        Return "File non trovato"
  End If

Code: Copy
SQLite1.InitializeSQLite(File.DirApp, "data.db", False)

Code: Copy
cs = SQLite1.ExecQuery(query)


Code: Copy
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: 509
e se data.db e' vuoto? esiste il file, si', ma senza tabelle... perche', non lo so da qui. mi domando.
 
Ho provato l'esempio di @LucaMs e funziona.
 
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.
 
Back
Top