还事数据库的问题,老是连接不上去
import java.sql.*;public class ConnectionSQLDemo
{
public ConnectionSQLDemo()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://localhost:1443;DatabaseName=java";
String userName = "sa";
String password = "";
Connection con = DriverManager.getConnection(url,userName,password);
String sql = "select * from studentTable";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
String studentName = rs.getString("studentName");
String studentID = rs.getString("studentID");
System.out.println("\n姓名:" + studentName + "学号:" + studentID);
}
st.close();
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException se)
{
se.printStackTrace();
}
}
public static void main(String[] args)//throws SQLException
{
new ConnectionSQLDemo();
}
}
我真的不知道我上面的代码哪里错了,请帮忙看看。
还有我想问一下,用什么方法可以判断数据库是否连接上了