错误提示:[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序.
网上搜了下,说可能是数据源的问题!!不太懂!!还请那位高人指点!!
程序代码:
package 建表;
import java.sql.*;
import sun.jdbc.odbc.JdbcOdbcDriver;
public class TableMaker {
Connection con;
Statement stmt;
static String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
static String dbName = "Contacts";
static String url = "jdbc:odbc:";
/**
* @param args
*/
static String SQLCreate =
"CREATE TABLE CONTACT_INFO (" +
"CONTACT_ID INTEGER NOT NULL PRIMARY KEY," +
"FIRST_NQME VARCHAR(20) NOT NULL," +
"MI CHAR(1) NULL," +
"LAST_NAME VARCHAR(30) NOT NULL," +
"STREET VARCHAR(30) NOT NULL," +
"CITY VARCHAR(30) NOT NULL," +
"STATE CHAR(2) NOT NULL," +
"ZIP VARCHAR(10) NOT NULL" +
");";
public TableMaker() {
registerDriver();
}
public void setDatabaseName(String dbName) {
this.dbName = dbName;
}
public void registerDriver() {
try {
Class.forName(jdbcDriver);
} catch(ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
public void execute(String SQLCommand) {
url += dbName;
try {
con = DriverManager.getConnection(url);
stmt = con.createStatement();
stmt.execute(SQLCommand);
con.close();
} catch(SQLException e) {
System.err.println(e.getMessage());
} finally {
try {
if(con != null) {
con.close();
} if(stmt != null) {
stmt.close();
}
} catch(Exception ex) {
System.err.println(ex.getMessage());
}
}
}
public static void main(String[] args) {
TableMaker tableMaker = new TableMaker();
tableMaker.execute(SQLCreate);
// TODO 自动生成方法存根
}
}
所用IDE: eclipse 数据库:SQL2000 JDK1.5