Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 我想问个数据源的问题(在java中调用).好久了还是弄不好.
iceriver2000





发贴: 29
积分: 0
于 2007-01-17 15:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我有个access数据库名字是yang.mdb 其中有表 project
我把它注册成文件dsn 为mydb.dsn
然后我要调用此表 那么请问我的mydb.dsn要放在什么目录下才能被xx.java文件识别??是不用考虑mydb.dsn的存放路径吗???还是一定 是和xx.java在一个目 录下??
还有如果将yang.mdb注册成系统数据源mydb1.dsn那么这个mydb.dsn要放在什么目录下 ??
一定 是和xx.java在一个目录下吗??

路径问题一直困饶我,如果问的很白痴 大家不要笑话 希望能指点小弟下.如果没时间的话帮我推荐下这方面的书籍或连接 小弟先谢过.



作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:iceriver2000]
iceriver2000





发贴: 29
积分: 0
于 2007-01-17 15:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我注册的文件dsn 名为 mydb.dsn放在和EmpJdbc.java 同一目录下的.
我的测试代码如下:
package prodb1;
import java.sql.*;

public class EmpJdbc {
String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:mydb";
Connection con=null;
ResultSet rs=null;
public EmpJdbc(){
try{
Class.forName(dbDriver);

}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
public ResultSet executeQuery(String s){
rs=null;
try{
con=DriverManager.getConnection(url);
Statement stm=con.createStatement();
rs=stm.executeQuery;

}catch(SQLException e){
e.printStackTrace();
}
return rs;
}
public static void main(String args[])throws Exception{
EmpJdbc emjdbc=new EmpJdbc();
String sql="SELECT*FROM project";
ResultSet rs=emjdbc.executeQuery(sql);
while(rs.next()){
String name=rs.getString("name");
System.out.println(name);

}
}

}
运行是老报 找不到 [ODBC]数据源 我都晕了,mydb.dsn都在empjdbc.java的同一级目录了啊.还找不到呢>



作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:iceriver2000]
wuzhong





发贴: 9
积分: 0
于 2007-01-17 22:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在我的电脑里odbc中设置电击micorsoft access driver这个驱动,然后设置数据源名,在连接数据库.这个只要路径对就可以了.


作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:iceriver2000]
iceriver2000





发贴: 29
积分: 0
于 2007-01-18 15:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是那样搞的 注册后的数据源文件 mydb.dsn 应该保存到什么地方呢?
是要放在和xx.java 的同一级目录下吗?
还是不论放在哪里 xx.java文件都能找到mydb.dsn文件呢?



作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:iceriver2000]
JiafanZhou



版主


发贴: 736
积分: 61
于 2007-01-18 18:35 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
为什么要注册成dsn呢?
有什么好处吗?
mdb可以直接被odbc.jdbc找到的阿。

关注。

嘉帆



When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.
作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:HenryShanley]
nanshanwentao





发贴: 4
积分: 0
于 2007-01-19 09:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不注册数据源怎么能找到呢


作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:iceriver2000]
wuzhong





发贴: 9
积分: 0
于 2007-01-19 14:03 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以了.
import java.sql.*;

public class EmpJdbc {
String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:mydb";
Connection con=null;
ResultSet rs=null;
public EmpJdbc(){
try{
Class.forName(dbDriver);

}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
public ResultSet executeQuery(String s){
rs=null;
try{
con=DriverManager.getConnection(url);
Statement stm=con.createStatement();
rs=stm.executeQuery("SELECT * FROM project");

}catch(SQLException e){
e.printStackTrace();
}
return rs;
}
public static void main(String args[])throws Exception{
EmpJdbc emjdbc=new EmpJdbc();
String sql="SELECT*FROM project";
ResultSet rs=emjdbc.executeQuery(sql);
while(rs.next()){
String name=rs.getString("name");
System.out.println(name);

}
}

}



作者 Re:我想问个数据源的问题(在java中调用).好久了还是弄不好. [Re:iceriver2000]
wuzhong





发贴: 9
积分: 0
于 2007-01-19 14:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
是这样的,在我的电脑里面----控制面版---odbc数据源管理---用户DSN---添加----------选择:Microsot Access Driver----电击完成按钮--数据源名:mydb,数据库点击选择,就是你保存的数据的文件路径.就可以了.
你的源程序有错误的.注意看一下.现在可以了.




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923