62,615
社区成员
发帖
与我相关
我的任务
分享
// Create_Table.java
import java.sql.*;
public class Create_Table {
public static void main(String[] args) {
//声明jdbc驱动程序类型
String JDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
//定义jdbc的URL对象
String conURL = "jdbc:odbc:TestDB";
// String conURL = "G:\\Debuging\\ProgrameDebuging\\Java\\Debugging\\odbc.accdb"; try {
//加载jdbc-odbc桥驱动程序
Class.forName(JDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.out.println("forname: " + e.getMessage());
}
try {
//连接数据库URL
Connection con = DriverManager.getConnection(conURL);//??数据库地址
//建立Statement类对象
Statement s = con.createStatement();
//创建一个含有3个字段的顾客表conumser
String query = "create table consumer(id char(10),"
+ "name char(15), totalmoney integer)";
s.executeUpdate(query); //执行SQL语句
s.close(); //释放statement所连接的数据库及jdbc资源
con.close(); //关闭与数据库的连接
}
catch(SQLException e) {
System.out.println("SQLException: " + e.getMessage());
}
}
}
String dbURL = "jdbc:subprotocol:subname://localhost:1433;DatabaseName=dbn";