importjava.sql.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassstudentInfextendsJFrame{JTextAreainfo=newJTextArea();JScrollPanePane1=newJScrollPa...
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class studentInf extends JFrame
{
JTextArea info=new JTextArea();
JScrollPane Pane1=new JScrollPane();
public studentInf()
{
super("学生信息");
setSize(400,200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Pane1.getViewport().add(info);
this.getContentPane().add(Pane1);
}
public void DBC (){
try{
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D://我的文档//access//db.mdb";//你的ACCESS文件位置
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(strurl);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from student_inf");
while(rs.next())
{
info.setText(rs.getString("student_no")+"\t");
info.append(rs.getString("student_name")+"\n");
}
rs.close();
stmt.close();
conn.close();
}catch(Exception e)
{
info.setText(e.getMessage());
}
}
public static void main(String[] args) throws ClassNotFoundException {
studentInf dbc = new studentInf();
dbc.DBC();
dbc.show();
}
}
展开