1. Connection con=DriverManager.getConnection(l,"sa",""); Connection con=DriverManager.getConnection(l,"sa"," "); The password is empty or one space?2. You may need a database name before USER1, sth. like [MEMBER].[SA].USER1. Or you should add the database name in your connection url.
package com.qiu.jdbc;
import java.net.*;
import java.sql.*;public class select { /**
* @param args
*/
public static void main(String[] args) {
String l="jdbc:odbc:test";
try{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println("ClassNotFountException: ");
System.err.println(e.getMessage());
}
Connection con=DriverManager.getConnection(l,"sa","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from USER1 ");
while(rs.next()){
for(int i=0;i<=3;i++)
System.out.println("这是第"+i+"个字符的内容"+rs.getString(i));
}
con.close();
}
catch(SQLException e){
while(e!=null){
System.out.println("数据库异常被捕获");
System.out.println(e.getMessage());
System.out.println(e.getErrorCode());
e=e.getNextException();
}
}
}
}
package com.qiu.jdbc;
import java.net.URL;
import java.sql.*;public class test { /**
* @param args
*/
public static void main(String[] args) {
String l="jdbc:odbc:test";
try{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e){
System.out.print("ClassNotFoundException:");
System.err.print(e.getMessage());
}
Connection con=DriverManager.getConnection(l,"sa"," ");
DatabaseMetaData dma=con.getMetaData();
System.out.println("连接的数据库:"+dma.getURL());
System.out.println("Driver :"+dma.getDriverName());
System.out.println("Vension :"+dma.getDriverVersion());
con.close();
}
catch(SQLException e){
while(e!=null){
System.out.println("数据库异常被捕获了");
System.out.println(e.getSQLState());
System.out.println(e.getMessage());
System.out.println(e.getErrorCode());
e=e.getNextException();
}
}
}
}
问下 用sqlserver2000 是不是一定要装补丁sp3的
Connection con=DriverManager.getConnection(l,"sa"," ");
The password is empty or one space?2. You may need a database name before USER1, sth. like [MEMBER].[SA].USER1.
Or you should add the database name in your connection url.