查询数据库为什么会报错con啊
package zou;
import java.sql.*;
public class chaxun {
public static void main(String args[]) {
Connection con=null ;
Statement sql;
ResultSet yx;
try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e) {
System.out.println(e);
}
String uri="jdbc:sqlserver://localhost:1433;DatabaseName=智慧停车场管理系统"+";trustServerCertificate=true";
String user="sa";
String password="zouyuxiang123";
try {
con = DriverManager.getConnection(uri,user,password);
}
catch(SQLException e) {
System.out.println(e);
}
System.out.println("正常连接数据库");
try {
sql=con.createStatement();
String TEL = "联系方式";
String CName = "车主姓名";
String PNo = "停车号";
String HNo = "门牌号";
System.out.printf("%s\t", TEL);
System.out.printf("%s\t", CName);
System.out.printf("%s\t", PNo);
System.out.printf("%s\t", HNo);
yx=sql.executeQuery("select * from 车主表");
while(yx.next()) {
String TEL1 = yx.getString(1);
String CName1 = yx.getString(2);
String PNO = yx.getString(3);
String HNo1 = yx.getString(4);
System.out.printf("\n%s\t", TEL1);
System.out.printf("%s\t", CName1);
System.out.printf("%s\t", PNo);
System.out.printf("%s\t", HNo1);
}
con.close();
}
catch(SQLException e) {
System.out.println(e);
}
}
}
结果如下