简体   繁体   中英

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

javac SQLiteJDBC.java

and i run it by using java -classpath ".;sqlite-jdbc-3.7.2.jar" SQLiteJDBC (Windows)

it gives exception as SQLite :: main :: org.sqlite.JDBC and my code is below

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

Adding Classes to the JAR File's Classpath

You may need to reference classes in other JAR files from within a JAR file.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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