Eclipse连接SQL Server200不成功

来源:百度知道 编辑:UC知道 时间:2024/06/20 00:00:32
我的代码是这样的:
import java.sql.*;
public class Test {
static Connection con;
static Statement stmt;
static ResultSet rs;
public static void main(String[] args){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("成功加载JDBC-ODBC桥驱动程序");
} catch (ClassNotFoundException e) {
System.err.println("加载失败");
}
try {
con=DriverManager.getConnection("jdbc:mysql://localhost/Lxc","Lxc","null");
System.out.println("连接成功");
} catch (SQLException e) {
System.err.println("连接失败");
}
try {
stmt=con.createStatement();
rs=stmt.executeQuery("select * from Student");
} catch (SQLException e) {
System.err.println("连接失败");
}
try {
while(rs.next()){
System.out.println(rs.getString(1));
}
} cat

再次谢谢,就怕百度说我们有问题,哈哈

DriverManager.getConnection("jdbc:mysql://localhost/Lxc","Lxc","null");
我想知道你用的是SLQ Server2000还是MY SQL?
主要是你的数据库连接写错了~

("jdbc:mysql://localhost/Lxc","Lxc","null")
有问题吧?那个null是空值,还是一个字符串密码为null?