我装的sql sever2000,系统为W2K,用的是sever 2005 for JDBC驱动,运行程序为下面的代码,
import java.sql.*;
public class testjdbc{
public static void main(String[] args){
try{
//load the Driver
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://222.27.110.17:1433;DatabaseName=mydb";
String user = "administrator";
String password = "woaiwojia";
//connecte to the server
Connection conn = DriverManager.getConnection(url,user,password);
// Connection conn = DriverManager.getConnection(url,user,password);
//send the SQL command
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM Student";
ResultSet rs = stmt.executeQuery(sql);
//output the result
System.out.println("=====SELECT * FROM Student=====");
System.out.println("Sno\t\tSname");
while(rs.next())
System.out.println(rs.getString("Sno")+ "\t\t" +rs.getString("Sname"));
//close the connecte
conn.close();
}
catch(SQLException e){
System.out.println("SQL State :" +e.getSQLState());
System.out.println("SQL Error Code :" +e.getErrorCode());
}
catch(Exception e){
e.printStackTrace();
}
}
}
import java.sql.*;
public class testjdbc{
public static void main(String[] args){
try{
//load the Driver
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://222.27.110.17:1433;DatabaseName=mydb";
String user = "administrator";
String password = "woaiwojia";
//connecte to the server
Connection conn = DriverManager.getConnection(url,user,password);
// Connection conn = DriverManager.getConnection(url,user,password);
//send the SQL command
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM Student";
ResultSet rs = stmt.executeQuery(sql);
//output the result
System.out.println("=====SELECT * FROM Student=====");
System.out.println("Sno\t\tSname");
while(rs.next())
System.out.println(rs.getString("Sno")+ "\t\t" +rs.getString("Sname"));
//close the connecte
conn.close();
}
catch(SQLException e){
System.out.println("SQL State :" +e.getSQLState());
System.out.println("SQL Error Code :" +e.getErrorCode());
}
catch(Exception e){
e.printStackTrace();
}
}
}
解决方案 »
- 从数据库中取数据(求助)
- myeclipse7.1 web project 不支持jstl 和 el表达式 !!!
- jsf的2个datatable的左右移动
- Socket如何建立与外网的连接,实现客户端和主机之间的相互访问!(答案明确者20分,有详细案例者50分)
- 求助:jsp中的request.getParameter(String varName)方法中的varName是变量该如何解决
- 把附件存放在非发布服务器上?应该怎么存取呢?
- jxl读取Excel时 读到空单元格的时候就报错
- Struts2 + spring + hibernate的问题
- 获取叫焦点位置
- 安装tomcat4.1.29后,登录管理界面时,提示:输入网络密码,(域:XDB)?
- servlet 可以把ResultSet 类型的参数传递给jsp页面吗?
- 大家帮我看看这是怎么回事,用代码总是连接不上!
SQL State:08001
SQL Error Code 0