0

如何获得 MS Access 数据库中定义的所有约束,如主键和外键。对于 MySql,我们使用describe table_name

同样,在 java 程序中使用 MS Access 的查询是什么?

4

1 回答 1

0
import java.sql.*;
public class DescQueryOutput{

  public static void main(String args[]) 
  {
      try 
      {
          Class.forName("com.mysql.jdbc.Driver");
          Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/test","root","root");
          Statement stmt = con.createStatement();
          String query = "DESC newaccount";

          ResultSet rs = stmt.executeQuery(query);
          System.out.println("COLUMN NAME\tDATATYPE\tNULL\tKEY\tDEFAULT\tEXTRA");
  while (rs.next())
  {
      System.out.print(rs.getString(1)+"\t");
      System.out.print(rs.getString(2)+"\t");
      System.out.print(rs.getString(3)+"\t");
      System.out.print(rs.getString(4)+"\t");
      System.out.print(rs.getString(5)+"\t");
      System.out.println(rs.getString(6));
  }
      }

      catch (SQLException e) {
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

      finally {
      }
  }
}
于 2013-03-12T07:28:53.537 回答