请问各位大虾有没有办法在JAVA中创建ACCESS数据库(*.mdb)?设置它的数据库密码?(100分)

  • 主题发起人 主题发起人 jackjack
  • 开始时间 开始时间
J

jackjack

Unregistered / Unconfirmed
GUEST, unregistred user!
最好有源代码!
 
给你一个SQLSERVER的例子,是通过ODBC数据源连的, 你也可下载最新的JDBC FOR SQLSERVER
public static String getsqlserver ()
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn =
DriverManager.getConnection ("jdbc:odbc:test", "yang", "yang");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select yang,xg from test");
// Iterate through the result and print the employee names
rset.next ();
String str_back="";
str_back=rset.getString("xg");
return str_back;
}
 
是创建ACCESS数据库,并且设置它的密码?
老兄,偏题了!
用Jdbc-Odbc桥连接,我早就连上了
 
这是 Java 能干得吗?
不过我帮你想了个方法,先用Access创建一个空的Database作为你的模板,需要在代码里面
创建就copy一个过去,改改名字就OK了,跟着建立连接、创建表和索引是标准SQL调用,应该
没有问题吧?
另外有一套JavaADO的冬冬也可以做,不过这是JNI平台相关的类库,并不推荐。
http://www.infozoom.de/ie/javaado.html
 
好象连不上
 
/*
* @(#)CreateCoffees.java 1.2 99/04/23
*
* Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software;
and ii) Licenseedo
es not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications;
or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import java.sql.*;

// Create the Coffee Table.
public class CreateCoffees {
public static void main(String args[]) {

String url = "jdbc:odbc:CafeJava";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url,
"Admin", "duke1");

stmt = con.createStatement();
stmt.executeUpdate(createString);

stmt.close();
con.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
 
不如先建立一个access.mdb 然后copy it !
 
在Java里动态建库呢?
 
用SQL语句
CREATE DATABASE...不就行了
 
我就没搞懂既然用java,为什么又要用access,感觉像是
用坦克运垃圾。
 
To小猪:
你讲话很不客气!也有道理!
不过你就是没办法实现啊!!!
 
为什么要让那褪色的微笑去祝福憔悴的面容?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
后退
顶部