इसके दो कारण हैं:
- पहले
PreparedStatement. के निष्पादन के बाद कनेक्शन बंद हो गया है getconएकinstance. का उपयोग करता हैlocal. के बजाय चर चर। इस वजह से वहीconnवेरिएबल (जिसे पहले बंद कर दिया गया था)getcon. पर वापस आ जाता है अगली बार बुलाया जाता है।
इसे ठीक करने के लिए, getcon और DBConnect स्थानीय conn declare घोषित करने के लिए संशोधित करने की आवश्यकता है चर और इसे वापस कर दें (वास्तव में, आपको DBConnect . की आवश्यकता नहीं है बिल्कुल), उदा.:
public Connection getcon(){
try{
Class.forName("com.mysql.jdbc.Driver");
String unicode="useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8";
return DriverManager.getConnection("jdbc:mysql://localhost:15501/duckdb?"+unicode, "root", "_PWD");
}catch(Exception ex){
System.out.println(ex.getMessage());
System.out.println("couldn't connect!");
throw new RuntimeException(ex);
}
}