简体   繁体   English

如何在Sqlite中创建数据库?

[英]How to create Database in Sqlite?

I have downloaded sqlite-jdbc-3.72.jar and don't know where to place it so it executed my code using command line as 我已经下载了sqlite-jdbc-3.72.jar,但不知道将其放置在何处,因此它使用命令行执行了我的代码,

javac SQLiteJDBC.java javac SQLiteJDBC.java

and i run it by using java -classpath ".;sqlite-jdbc-3.7.2.jar" SQLiteJDBC (Windows) 我使用java -classpath“。; sqlite-jdbc-3.7.2.jar” SQLiteJDBC (Windows)运行它

it gives exception as SQLite :: main :: org.sqlite.JDBC and my code is below 它给异常,如SQLite :: main :: org.sqlite.JDBC ,我的代码如下

import java.sql.*;

public class SQLiteJDBC
{
    public static void main(String ar[])
    {
        Connection c = null;

        try
        {
            Class.forName("org.sqlite.JDBC");
            c = DriverManager.getConnection("jdbc:sqlite:test.db");
        }
        catch(Exception e)
        {
            System.out.println("SQLite :: main :: "+e.getMessage());
            System.exit(0);
        }
    System.out.println("Opened database successfully");
    }


}

You can take a look to : http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html 您可以看一下: http : //docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Adding Classes to the JAR File's Classpath 将类添加到JAR文件的类路径中

You may need to reference classes in other JAR files from within a JAR file. 您可能需要从JAR文件中引用其他JAR文件中的类。

For example, in a typical situation an applet is bundled in a JAR file whose manifest references a different JAR file (or several different JAR files) that serves as utilities for the purposes of that applet. 例如,在典型情况下,小程序捆绑在一个JAR文件中,其清单引用了一个不同的JAR文件(或几个不同的JAR文件),该文件充当该小程序的用途。

You specify classes to include in the Class-Path header field in the manifest file of an applet or application. 您可以指定要包含在小程序或应用程序清单文件中“类路径”头字段中的类。 The Class-Path header takes the following form: Class-Path标头采用以下形式:

Class-Path: jar1-name jar2-name directory-name/jar3-name

So, in your case it would be something like 因此,在您的情况下,

java -classpath sqlite-jdbc-3.7.2.jar SQLiteJDBC 

It should do the trick 它应该可以解决问题

尝试将命令更改为:

java -classpath ".:sqlite-jdbc-3.7.2.jar" SQLiteJDBC 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM