如何将Java连接到SQLite数据库浏览器。

huangapple 未分类评论48阅读模式
英文:

how can i connect java to sqlite db browser

问题

我正在尝试使用Nano编辑器将SQLite数据库浏览器与Java连接,我在这里非常新手。我已经按照一些YouTube视频的步骤进行了操作,但我在中途遇到了问题,有人可以帮忙吗?以下是我的代码。

import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqliteDB{

    Connection c = null;
    Statement stmt = null;

    SqliteDB(){
        try{
            Class.forName("org.sqlite.JDBC");
            c = DriverManager.getConnection("jdbc:sqlite:signup.db");
            System.out.println("已连接到数据库");
        }
        catch(Exception e){
            System.out.println("错误: " + e.getMessage());
        }
    }
}

错误信息:org.sqlite.JDBC
感谢大家的帮助。

英文:

I am trying to connect sqlite db browser with java using nano editor i am very new here. i have
followed some youtube videos but i am stacking at mid can anyone please help
here is my code.

import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqliteDB{

Connection c = null;
Statement stmt = null;

SqliteDB(){
try{
 Class.forName("org.sqlite.JDBC");

 c = DriverManager.getConnection("jdbc:sqlite:signup.db");
  System.out.println("Connected to DB");

  }
  catch(Exception e){
    System.out.println("Error: "+ e.getMessage());

  }
 }
 }


  Error: org.sqlite.JDBC
 thank you guys for helping. 

答案1

得分: 0

我认为你在项目中未导入库org.sqlite.JDBC,Class.forName()返回存在的类,当你遇到类似错误时,它表示该类不存在。

首先从以下链接下载库:https://bitbucket.org/xerial/sqlite-jdbc/downloads/

然后在你的项目中导入它,以下是你应该编写的代码:

public static void main(String[] args) throws SQLException {
    org.sqlite.JDBC j = new org.sqlite.JDBC();
    Connection c = DriverManager.getConnection("jdbc:sqlite:signup.db");
    // 在这里进行操作
}
英文:

I think that you have not imported library org.sqlite.JDBC in your project, Class.forName() return class that exists, when you get error like this it says that this class is not exists.

First of all download library from: https://bitbucket.org/xerial/sqlite-jdbc/downloads/

Then import in your project and that's how you should write the code:

public static void main(String[] args) throws SQLException {
        org.sqlite.JDBC j =  new org.sqlite.JDBC();
        Connection c = DriverManager.getConnection("jdbc:sqlite:signup.db");
        //do stuff here
    }

huangapple
  • 本文由 发表于 2020年7月27日 12:26:53
  • 转载请务必保留本文链接:https://java.coder-hub.com/63108712.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定