Java 更改用户JDBC连接
我正在尝试更改连接到我的数据库的用户,但它不起作用,我只能使用第一个。我该怎么做Java 更改用户JDBC连接,java,jdbc,connection,Java,Jdbc,Connection,我正在尝试更改连接到我的数据库的用户,但它不起作用,我只能使用第一个。我该怎么做 public class Model { private String user; private String passwd; private String url; private String matricule; private static Model model; private Connection connect; private Docto
public class Model {
private String user;
private String passwd;
private String url;
private String matricule;
private static Model model;
private Connection connect;
private DoctorsModel doctorsModel;
private ConnexionModel connexionModel;
private MedicineModel medicineModel;
private VisitorsModel visitorsModel;
private ReportModel reportModel;
private NewReportModel newReportModel;
private Model(String user, String passwd){
this.user = user;
this.passwd = passwd;
url="myurl";
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver OK");
this.connect = DriverManager.getConnection(url, user, passwd);
this.connexionModel = new ConnexionModel(connect,url,user,passwd);
this.doctorsModel = new DoctorsModel(connect);
this.medicineModel = new MedicineModel(connect);
this.visitorsModel = new VisitorsModel(connect);
this.reportModel = new ReportModel(connect);
this.newReportModel = new NewReportModel(connect,matricule);
}
catch (Exception e){
Alert error = new Alert(Alert.AlertType.WARNING);
error.setTitle("Erreur");
error.setHeaderText(null);
error.setContentText("Une erreur a été rencontrée, veuillez réessayer plus tard.");
error.showAndWait();
System.exit(0);
e.printStackTrace();
}
}
public static Model getInstance()
{
if (model==null)
{
model = new Model("firstuser","passwd");
}
return model;
}
public ConnexionModel getConnexionModel()
{
return connexionModel;
}
public DoctorsModel getDoctorsModel()
{
return doctorsModel;
}
public MedicineModel getMedicineModel()
{
return medicineModel;
}
public VisitorsModel getVisitorsModel()
{
return visitorsModel;
}
public ReportModel getReportModel()
{
return reportModel;
}
public NewReportModel getNewReportModel()
{
return newReportModel;
}
public void setUser(String user)
{
this.user = user;
}
public void setPasswd(String passwd)
{
this.passwd = passwd;
}
public void setConnection()
{
try
{
connect = DriverManager.getConnection(url,user,passwd);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void getConnection()
{
System.out.println(connect);
}
public void setMatricule(String matricule)
{
this.matricule = matricule;
}
public String getMatricule(String matricule)
{
return matricule;
}}
我在我的
ConnectionController
上调用setConnection()
,没什么特别的,我在前后打印了连接,打印了用户、密码,一切都正确更改了。。。在再次设置之前,我尝试关闭连接,但它只是告诉我连接已关闭,我无法再进行任何访问。您是否检查了异常消息?请将其附在您保留模型对象中第一个连接的引用的问题上this.doctorsModel=new doctorsModel(connect)代码>。。。好吧,我很笨。除息的