初学数据库,求助
第一次用java连接数据库,用的是SQLServer
代码如下:
import java.io.*;
import java.sql.*;
public class ConDB
{
public static void main(String[] args)
{
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StudentManage";
String user = "dbo";
String password = "";
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection(url,user,password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Course");
String s = rs.getString(1);
System.out.println(s);
try
{
System.in.read();
}catch(IOException i){}
}catch(SQLException se)
{
System.out.println("SQL Error!");
try
{
System.in.read();
}catch(IOException i){}
}
catch(ClassNotFoundException cfe)
{
System.out.println(cfe.toString());
try
{
System.in.read();
}catch(IOException i){}
}
catch(Exception ie){}
}
}
为什么老是出现SQLError呢?
谢谢