Sqlite db Connect - Java JDBC

Java examples for JDBC:Connection

Description

Sqlite db Connect

Demo Code


//package com.java2s;

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    public static Statement dbConnect() throws ClassNotFoundException {

        Class.forName("org.sqlite.JDBC");
        Connection connection = null;

        try {//from  w  w  w .j  av a2  s  .  c o m
            // create a database connection
            connection = DriverManager
                    .getConnection("jdbc:sqlite:/home/subset_artist_term.db");
            Statement statement = connection.createStatement();
            statement.setQueryTimeout(30); // set timeout to 30 sec.
            return statement;
        } catch (SQLException e) {
            // if the error message is "out of memory",
            // it probably means no database file is found
            System.err.println(e.getMessage());
        }
        return null;
    }
}

Related Tutorials