java中sql server连接问题

wanlili517 2006-04-13 09:02:20
我下载了jdbc驱动程序,可是写下如下代码,总说我找不到驱动程序。请各位高手帮帮忙哦!!十分感谢!!!
import java.sql.*;

public class database {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user = "wl";
String password = "wl";
Connection conn = DriverManager.getConnection(url, user, password);
user=sa&password=hbkj";
Statement sqlStatement = conn.createStatement();
String sql = "select job_id,job_desc from jobs";
ResultSet results = sqlStatement.executeQuery(sql);
while (results.next()) {
String resultDisplay = " ";
resultDisplay = resultDisplay + results.getString("job_id");
resultDisplay = resultDisplay + ","+ results.getString("job_desc");
resultDisplay = resultDisplay + "\n";
System.out.println(resultDisplay);
}
conn.close();
}
catch(ClassNotFoundException e){
System.out.println("找不到驱动程序");
}catch (SQLException e) {
} catch (Exception e) { }

}
...全文
93 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuzl32 2006-04-13
  • 打赏
  • 举报
回复
将驱动放到CLASSPATH中

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧