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);
      
    }
  }

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



作者 Re:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
xuelange





发贴: 1
积分: 0
于 2007-01-09 09:12 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是否准确。
检查是否存在连对数据库,表和表的列名Smile



作者 Re:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
qw2008





发贴: 3
积分: 0
于 2007-01-11 17:56 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:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
gwangmm





发贴: 1
积分: 0
于 2007-01-12 15:25 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:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2007-01-12 20:11 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
SELECT * FROM Project


作者 Re:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
jg0021





发贴: 4
积分: 0
于 2007-01-16 20:43 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 calss ExcuteSQL{
ExcuteSQL(){}

Connection conn=null;

}



作者 Re:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
wuzhong





发贴: 9
积分: 0
于 2007-01-17 23: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
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="SELLECT*FROM project";
ResultSet rs=emjdbc.executeQuery(sql);
while(rs.next()){
String name=rs.getString("name");
System.out.println(name);

}
}

}



作者 Re:请教个连接数据库的连接问题(有代码) 谢过先 [Re:iceriver2000]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2007-01-20 19:24 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
SELLECT*FROM project
SELECT * FROM project


and error message, please.




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