Home > Computer Tutorials > Computer Knowledge > How to create a database using Java and Access

How to create a database using Java and Access

WBOY
Release: 2024-01-25 09:33:16
forward
965 people have browsed it

How to create a database using Java and Access

How to create a database using Access in java

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.*;

public class connODBC {

public static Statement stmt;

public static ResultSet rs;

String sql;

public static void main(String[] args) {

connODBC task=new connODBC();

task.ConnectionODBC();

}

public void ConnectionODBC() {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=table.mdb";

Connection con = DriverManager.getConnection(url);

System.out.println ("Data source connection successful...");

stmt=con.createStatement();

} catch (SQLException e) {

System.out.println(e.getMessage());

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

}

}

Note: The table.mdb file must be in the directory where the .java file is located and must exist.

Master, take a look at the problem of JAVA connecting to the ACCESS database

Answer class tes {

private String url;

private Connection con=null;

public tes() throws ClassNotFoundException,SQLException{

Class.forName("sun.jdbc.odbc.JdbcOdbcDrier");

url="jdbc:odbc:Driver={Microsoft Access Driver(*.mdb,*.accdb)};DBQ=E:/java/workspace/BankSystem/src/bank.accdb";

con=DriverManager.getConnection(url);

System.out.println("ok");

}

public static void main(String[] args){

try {

new tes();

} catch (Exception e) {

e.printStackTrace();

}

}

}

The following means that there is a problem with your driver, please take a closer look.

The above is the detailed content of How to create a database using Java and Access. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template