import java.sql.*;
import sun.jdbc.odbc.JdbcOdbcDriver;
public class TableMaker {
static String jdbcDriver="sun.jdbc.odbc.JdbcOdbcDriver";
static String dbName="Contacts";
static String url="jdbc:odbc:";
static String SQLCreate=
"CREATE TABLE CONTACT_INFO("+
"CONTACT_ID INTEGER NOT NULL PRIMARY KEY,"+
"FIRST_NAME VARCHAR(20) NOT NULL,"+
"MI CHAR(1) NULL,"+
"LAST_NAME VARCHAR(30) NOT NULL,"+
"STREET VARCHAR(50) 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.print(e.getMessage());
}
}
public void execute(String SQLCommand){
url+=dbName;
Connection con = null;
Statement stmt = null;
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){}
}
}
public static void main(String[] args){
TableMaker tableMaker=new TableMaker();
tableMaker.execute(SQLCreate);
}}
显示[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
因为是直接在代码里写语句 怎么用SQL2000配数据源哈 谢谢了 在线等答案