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

您没有登录

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

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请教个连接数据库的连接问题(有代码) 谢过先
iceriver2000





发贴: 29
积分: 0
于 2007-01-08 12:08 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
我有个数据库叫project.mdb(access的) 注册数据源为 mydb.dsn 其中有表为project
要在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.executeQueryMoon;
      
    }catch(SQLException e){
      e.printStackTrace();
    }
    return rs;
  }
  public static void main(String args[])throws Exception{
    EmpJdbc emjdbc=new EmpJdbc();
    String sql="SELLECT*FROM project";
    ResultSet rs=emjdbc.executeQuery(sql);
    while(rs.next()){
      String name=rs.getString("name");
      System.out.println(name);
      
    }
  }

}
理论上是可以的啊 ,为什么我搞一天 老是给我报错呢 ??
请大家帮帮小弟 感激不尽.




话题树型展开
人气 标题 作者 字数 发贴时间
8447 请教个连接数据库的连接问题(有代码) 谢过先 iceriver2000 977 2007-01-08 12:08
6849 Re:请教个连接数据库的连接问题(有代码) 谢过先 xuelange 39 2007-01-09 09:12
6934 Re:请教个连接数据库的连接问题(有代码) 谢过先 qw2008 10 2007-01-11 17:56
6840 Re:请教个连接数据库的连接问题(有代码) 谢过先 gwangmm 10 2007-01-12 15:25
6789 Re:请教个连接数据库的连接问题(有代码) 谢过先 why 21 2007-01-12 20:11
6736 Re:请教个连接数据库的连接问题(有代码) 谢过先 jg0021 113 2007-01-16 20:43
7075 Re:请教个连接数据库的连接问题(有代码) 谢过先 wuzhong 903 2007-01-17 23:03
6854 Re:请教个连接数据库的连接问题(有代码) 谢过先 why 86 2007-01-20 19:24

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