jdbc驱动程序连接数据库_使用JDBC Type-1驱动程序连接到Access数据库

本文介绍了如何使用JDBC-ODBC Bridge驱动程序将Java应用与Access数据库连接,包括创建DSN名称的步骤。需要注意的是,从Java 8开始,JDBC-ODBC Bridge已被移除并不再支持。
摘要由CSDN通过智能技术生成

jdbc驱动程序连接数据库

To connect a Java application with Access database using JDBC-ODBC Bridge(type-1) Driver. You need to follow the following steps.

使用JDBC-ODBC Bridge(type-1)驱动程序将Java应用程序与Access数据库连接。 您需要执行以下步骤。

Note: In Java 8, the JDBC-ODBC Bridge has been removed. It is no longer supported.

注意:在Java 8中,已删除JDBC-ODBC桥。 不再受支持。

创建DSN名称 (Create DSN Name)

  1. Go to control panel

    转到控制面板

    Connecting to access
  2. Go to Administrative tools

    转到管理工具

    Connecting to access
  3. Select Data Source(ODBC)

    选择数据源(ODBC)

    Connecting to access
  4. Add new DSN name, select add

    添加新的DSN名称,选择添加

    Connecting to access
  5. Select Access driver from the list, click on finish

    从列表中选择Access driver,单击Finish。

    Connecting to access
  6. Give a DSN name, click ok

    输入DSN名称,然后单击“确定”。

    Connecting to access

NOTE: Here we are showing this example to create DSN in Window 7 os. For other operating system you need to do small changes.

注意:这里我们展示了在Windows 7操作系统中创建DSN的示例。 对于其他操作系统,您需要进行一些小的更改。

时间为例! (Time for an Example!)

We suppose that you have created a student table with sid and name column name in access database.

我们假设您已经在访问数据库中创建了一个带有sid和name列名的学生表。

import java.sql.*;
class Test
{
  public static void main(String []args)
  {
    try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con = DriverManager.getConnection("jdbc:odbc:Test", "", "");
      Statement s=con.createStatement();        //creating statement

      ResultSet rs=s.executeQuery("select * from student");     //executing statement

      while(rs.next()){
         System.out.println(rs.getInt(1)+" "+rs.getString(2));
      }

      con.close();      //closing connection

    }
    catch(Exception e)
    {
       e.printStackTrace();
    }
  }
}

翻译自: https://www.studytonight.com/java/connecting-to-access.php

jdbc驱动程序连接数据库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值