如何获取MS Access数据库中定义的主键和外键等所有约束。
对于MySql,我们使用describe table_name
同样,MS Access在java程序中使用它的查询是什么?
答案 0 :(得分: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 {
}
}
}