以文本方式查看主题 - 计算机科学论坛 (http://bbs.xml.org.cn/index.asp) -- 『 XML 与 数据库 』 (http://bbs.xml.org.cn/list.asp?boardid=17) ---- [求助]这是一个有关SQL数据库创建表的程序,请各位帮忙看看怎么能调通! (http://bbs.xml.org.cn/dispbbs.asp?boardid=17&rootid=&id=18469) |
-- 作者:zhaozhenbing001 -- 发布时间:5/18/2005 9:56:00 AM -- [求助]这是一个有关SQL数据库创建表的程序,请各位帮忙看看怎么能调通! import java.sql.*; import sun.jdbc.odbc.JdbcOdbcDriver; public class TableMaker { static String jdbcDriver="sun.jcbc.odbc.JdbcOdbcDriver"; static String dbName="zhaozhenbing"; 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); DriverManager.registerDriver(new JdbcOdbcDriver()); } catch(ClassNotFoundException exp) { System.err.println(exp.getMessage()); } catch(SQLException e) { System.err.println(e.getMessage()); } } public void execute(String SQLCommand) { url+=dbName; Connection con; Statement stmt; 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); } } |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
31.250ms |