数据库怎么运行不出来
import java.sql.Connection;import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Test17 {
private Connection con;
public static void main(String[] args) {
}
public void getStudent(Connection con,String sql){
try{
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next()){
String name1=rs.getString(1);
String code1=rs.getString(2);
String sexy1=rs.getString(3);
String age1=rs.getString(4);
System.out.println("\nname"+name1+"\tcode"+code1+"\tsexy"+sexy1+"\tage"+age1);
}
st.close();
con.close();
}catch(Exception e){
System.out.println(e);
}
}
public Connection getConnection(){
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=student"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "123"; //密码
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}