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

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MS SQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 读数据库sql2000失败,高手来帮忙看看
xuebing





发贴: 5
积分: 0
于 2004-09-24 14:57 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 JDBCTest{
  public static void main(String args[]){
    String url="jdbc:odbc:company";
    String user="sa";
    String password="sa";
    String ls_1="select * from employee";
    
    try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con=DriverManager.getConnection(url,user,password);
      Statement stmt=con.createStatement();
      ResultSet rs=stmt.executeQuery(ls_1);
      System.out.print("firstname ");
      System.out.print("lastname ");
      System.out.print("age ");
      System.out.print("address ");
      System.out.print("city ");
      while(rs.next()){
        System.out.print(rs.getString(1)+"|");
        System.out.print(rs.getString(2)+"|");
        System.out.print(rs.getInt(3)+"|");
        System.out.print(rs.getString(4)+"|");
        System.out.println(rs.getString(5));
      }
      rs.close();
      stmt.close();
      con.close();
    }
    catch(SQLException sqle){
      System.out.println(1+sqle.toString());
    }
    catch(Exception e){
      System.out.println(2+e.toString());
    }
  }
}
运行结果:1java.sql.SQLException:[Micr0soft][ODBC驱动程序管理器]未发现数据源名称并且未指定默认驱动程序

是什么原因?




话题树型展开
人气 标题 作者 字数 发贴时间
8798 读数据库sql2000失败,高手来帮忙看看 xuebing 1131 2004-09-24 14:57
7634 Re:读数据库sql2000失败,高手来帮忙看看 lovefan 55 2004-09-24 15:08
7615 Re:读数据库sql2000失败,高手来帮忙看看 xuebing 147 2004-09-25 02:03
7593 Re:读数据库sql2000失败,高手来帮忙看看 xuebing 21 2004-09-25 09:33
7615 Re:读数据库sql2000失败,高手来帮忙看看 xuebing 135 2004-09-25 23:01
7511 Re:读数据库sql2000失败,高手来帮忙看看 why 137 2004-09-25 23:22
7622 Re:读数据库sql2000失败,高手来帮忙看看 xuebing 141 2004-09-26 00:12
7700 Re:读数据库sql2000失败,高手来帮忙看看 momoxiao 2777 2004-09-29 12:04
7845 Re:读数据库sql2000失败,高手来帮忙看看 debug148 7 2004-10-09 21:52
7667 Re:读数据库sql2000失败,高手来帮忙看看 hanju 41 2004-10-10 08:37
8209 Re:读数据库sql2000失败,高手来帮忙看看 bill1 9 2004-10-19 16:32

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