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)
Go to control panel
转到控制面板
Go to Administrative tools
转到管理工具
Select Data Source(ODBC)
选择数据源(ODBC)
Add new DSN name, select add
添加新的DSN名称,选择添加
Select Access driver from the list, click on finish
从列表中选择Access driver,单击Finish。
Give a DSN name, click ok
输入DSN名称,然后单击“确定”。
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驱动程序连接数据库