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

How to create a database using Java and Access

WBOY
WBOYforward
2024-01-25 09:33:16944browse

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!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete