This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.*; | |
public class password { | |
public static void main(String[] args) { | |
try{ | |
// | |
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); | |
// | |
// Connection con=DriverManager.getConnection("jdbc:odbc:passwd"); | |
// Connection con= setupConnection(); | |
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); | |
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};" + | |
"DBQ=c:\\mdb\\passwd.MDB"); | |
// | |
Statement stmt = con.createStatement(); | |
// | |
String sql = "SELECT * FROM password"; | |
// | |
ResultSet rs = stmt.executeQuery(sql); | |
// | |
while(rs.next()){ | |
// | |
int uniq_id = rs.getInt("uniq_id"); | |
// | |
String keyword = rs.getString("keyword"); | |
// | |
String password = rs.getString("password"); | |
// | |
String date = rs.getString("date"); | |
// | |
System.out.println(uniq_id + " " + keyword + " " + password + " " + date); | |
} | |
stmt.close(); | |
con.close(); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
} |
http://stackoverflow.com/questions/5016730/creating-a-dsn-less-connection-for-ms-access-within-java
なお、ODBCでDSN登録を行ってから、接続する方法は以下に記述しました。
http://chaos-fractal.blogspot.jp/2012/09/java-access-mdb.html
(2014.7.10)この方法は、 Java 8 になってからは使用できなくなりました。その理由は以下のページで説明させていただいております。
http://chaos-fractal.blogspot.jp/2014/07/java-access-jdbc-odbc.html
0 件のコメント:
コメントを投稿