Java 如何使小程序与MS Access数据库连接?
编写一个小程序,显示 所述程序的接口 在下面执行小程序时,它将 将在中显示屏幕 适当的布局,并响应 用户的操作 这个程序模拟一个学生 具有以下特性的管理系统 特点: 界面很吸引人,非常人性化 友好、直观(即充当 有人会期望它行动起来),并且 相当现实。它必须接受 学生id、姓名、年龄、地址、日期 出生、性别、血型等 选择用户并将其保存在MS Access中 数据库+电子邮件Id、电话号码、级别 界面使用命令按钮来 (i) 添加、编辑、删除、更新和取消 记录,(ii)导航 向前或向后记录(iii)到 直接移动到第一条记录或最后一条记录 记录记录的数量 输入的内容应使用 当用户按下按钮时报告 “报告”按钮 最初使所有字段不可见 或者把它涂成灰色 在接口中适当地使用 至少一套“单选按钮”和 至少有一个“下拉列表”。制作 布局的适当使用 经理Java 如何使小程序与MS Access数据库连接?,java,ms-access,jdbc,applet,Java,Ms Access,Jdbc,Applet,编写一个小程序,显示 所述程序的接口 在下面执行小程序时,它将 将在中显示屏幕 适当的布局,并响应 用户的操作 这个程序模拟一个学生 具有以下特性的管理系统 特点: 界面很吸引人,非常人性化 友好、直观(即充当 有人会期望它行动起来),并且 相当现实。它必须接受 学生id、姓名、年龄、地址、日期 出生、性别、血型等 选择用户并将其保存在MS Access中 数据库+电子邮件Id、电话号码、级别 界面使用命令按钮来 (i) 添加、编辑、删除、更新和取消 记录,(ii)导航 向前或向后记录(iii)
通过将MS access数据库添加到ODBC源中,可以访问该数据库 要打开数据源(ODBC),请单击开始,单击控制面板,然后单击性能和维护。单击管理工具,然后双击数据源(ODBC) 下面是一些您可以熟悉的示例代码。看看相关的类和方法——您将在其中找到与数据库交互的几乎所有答案。是的,这里存在一些与visualswing类的可怕耦合(您应该抛出一个错误,而不是仅仅显示一个错误并强制系统退出)。此外,我认为JdbcOdbcDriver的使用也不受欢迎
import javax.swing.*;
import sun.jdbc.odbc.JdbcOdbcDriver;
import java.sql.*;
import java.util.*;
public class SalesDB
{
private static Connection connect;
/**
* Connects to the database. This method must be run before any of the other methods since
* this method enables the connection to the database.
*/
public static void connect()
{
//The 'a5q3db' is the name of the ODBC source that you added.
String url = "jdbc:odbc:a5q3db";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connect = DriverManager.getConnection(url);
}
catch (ClassNotFoundException ex)
{
JOptionPane.showMessageDialog(null, "Failed to load JDBC/ODBC driver. Program will now terminate.");
System.exit(-1);
}
catch (SQLException ex)
{
JOptionPane.showMessageDialog(null, "Failed to connect to the database. Program will now terminate.");
System.exit(-1);
}
}
/**
* close the database connection before the program terminates.
*/
public static void close()
{
try
{
connect.close();
}
catch (SQLException ex)
{
}
}
/**
* Runs the supplied string as a query to the database and returns the result set.
* @param query The query with which to execute to the database.
* @return The generated resultset from java.sql.Statement#executeQuery(String).
*/
public static ResultSet runQuery (String query)
{
ResultSet result;
try
{
Statement statement = connect.createStatement();
result = statement.executeQuery(query);
}
catch (SQLException ex)
{
return null;
}
return result;
}
}//End SalesDB class.
好吧,你到底在哪一步结巴?这就是你感兴趣的问题。把你已经做过的事情贴出来。请遵循问题,说明任何特殊的限制,展示你迄今为止所做的尝试,并询问具体是什么让你感到困惑。