What is wrong with my update query, parameter not set error - java

I am beginner of java and this is the change password coding.I tried to use update query to update the password.But something wrong with my coding.Can someone help me to find it out? After i execute, occur the error:
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.1 Parameter not set
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:256)
at UserPassword.actionPerformed(UserPassword.java:142)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLException: Parameter not set
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.checkParametersSet(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
at net.ucanaccess.jdbc.ExecuteUpdate.executeWrapped(ExecuteUpdate.java:65)
at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:208)
at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50)
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:253)
... 37 more
Caused by: org.hsqldb.HsqlException: Parameter not set
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
... 45 more
public void actionPerformed(ActionEvent action)
{
if(action.getSource() == backButton)
{
dispose();
}
String userName = field1.getText();
char [] s1 = field2.getPassword();
char [] s2 = field3.getPassword();
String userpass = new String(s1);
String userpass2 = new String(s2);
try
{
String UpdateQuery = null;
PreparedStatement st = null;
Connection connect = DriverManager.getConnection("jdbc:ucanaccess://Database.accdb");
if(action.getSource() == changeButton)
{
UpdateQuery = "UPDATE STUDENT SET StudentID = ?, Password = ? WHERE StudentID = ?";
st = connect.prepareStatement(UpdateQuery);
if(userpass.equals(userpass2))
{
st.setString(1, userName);
st.setString(2, userpass2);
st.executeUpdate();
JOptionPane.showMessageDialog(this,"Username and Password changed!","Student",JOptionPane.INFORMATION_MESSAGE);
dispose();
UserPage up = new UserPage(null);
connect.close();
}
else if(userpass != userpass2)
{
JOptionPane.showMessageDialog(this,"Password not match!","Password error",JOptionPane.ERROR_MESSAGE);
}
}
}
catch (SQLException e1)
{
e1.printStackTrace();
}
reset();
}
}

You have three ? but only two parameter setup. You are missing the third parameter.
st.setString(3, userId);

Related

"java.sql.SQLException: No database selected" with MySQL JDBC [duplicate]

This question already exists:
Error:java.sql.SQLSyntaxErrorException: Table 'loginpass.intousers' doesn't exist [duplicate]
Closed 3 years ago.
Code:
Connection dbConnection;
public Connection getDbConnection() throws ClassNotFoundException, SQLException{
String connectionString = "jdbc:mysql://127.2.0.1:3306/?user=root?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false";
;
String url="?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
Class.forName("com.mysql.jdbc.Driver");
dbConnection = DriverManager.getConnection(connectionString, dbUser, dbPass);
return dbConnection;
}
public void SingUpUser(String id,String login, String password) {
String insert = "INSERT INTO"+Constant.USER_TABLE+"("+Constant.USERS_ID+","+Constant.USERS_LOGIN+","+Constant.USER_PASSWORD+")"+
"VALUES(?,?,?)";
try {
PreparedStatement prSt = getDbConnection().prepareStatement(insert);
prSt.setString(1, id);
prSt.setString(2, login);
prSt.setString(3, password);
prSt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Error:
java.sql.SQLException: No database selected
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:955)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1094)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1042)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1345)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1027)
at minelaunch.Databases.SingUpUser(Databases.java:36)
at minelaunch.minelauncherv1$5.actionPerformed(minelauncherv1.java:182)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I expect to write to the database, but I get this error.
From the stack trace:
java.sql.SQLException: No database selected
You have removed the database name from your connection string, so now MySQL does not know which database you want to work with. Edit your connection string again and specify the actual name of the database you want to use.

unable to write data in sql database by java but reading successfully

I'm using the code below:
JButton btnEdit = new JButton("Edit");
btnEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try{
String query = "Insert Into check(Name, Password)Values(?,?)";
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1, textField.getText());
pst.setString(2, textField_1.getText());
/* pst.setString(3, textField_2.getText());
pst.setString(4, textField_4.getText());
pst.setString(5, textField_5.getText());
*/
pst.execute();
JOptionPane.showMessageDialog(null, "Data Saved");
pst.close();
}catch(Exception e){
e.printStackTrace();
}
}
});
I am retrieving data from a SQL database, but whenever I try to insert data, I get errors during runtime:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL
Server]Incorrect syntax near the keyword 'check'. at
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at
sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source) at
sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source) at
AdminPanel$2.actionPerformed(AdminPanel.java:184) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source) at java.awt.Component.processMouseEvent(Unknown Source) at
javax.swing.JComponent.processMouseEvent(Unknown Source) at
java.awt.Component.processEvent(Unknown Source) at
java.awt.Container.processEvent(Unknown Source) at
java.awt.Component.dispatchEventImpl(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Window.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.awt.EventQueue.access$300(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue$4.run(Unknown Source) at
java.awt.EventQueue$4.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run (Unknown Source)
'check' is a reserved keyword and so code is failing, trying with a name which is not a keyword should solve the issue.

How to upload RDF code to fuseki server using Java?

I wrote a function that convert data to RDF and I need to upload this RDF to the fuseki server.
I tried to implement the code from here as follows
public class GenerateRDF {
public void setRDF(String[] personalData ) {
String serviceURI = "http://localhost:3030/Date";
DatasetAccessorFactory factory = null;
DatasetAccessor accessor;
accessor = factory.createHTTP(serviceURI);
String name = personalData[0];
String nationality = personalData[1];
String date = personalData[2];
String address = personalData[3];
String mobile = personalData[4];
String email = personalData[5];
String website = personalData[6];
String profesional = personalData[7];
String education = personalData[8];
String communication = personalData[9];
String digital = personalData[10];
String professional = personalData[11];
String management = personalData[12];
String certifications = personalData[13];
InputStream in = null;
Model model = ModelFactory.createDefaultModel();
Resource node = model.createResource(personURI)
.addProperty(FOAF.name, name)
.addProperty(FOAF.member, nationality)
.addProperty(FOAF.birthday, date)
.addProperty(FOAF.homepage, address)
.addProperty(FOAF.phone, mobile)
.addProperty(FOAF.yahooChatID, email)
.addProperty(FOAF.weblog, website)
.addProperty(FOAF.plan, profesional)
.addProperty(FOAF.knows, education)
.addProperty(FOAF.depiction, communication)
.addProperty(FOAF.interest, digital)
.addProperty(FOAF.publications, professional)
.addProperty(FOAF.maker, management)
.addProperty(FOAF.made, certifications);
String base = "http://test-projects.com/";
model.read(in, base, "RDF/XML");
accessor.putModel(model);
model.write(System.out);
}
}
Which returns the following Exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.readAndBuffer(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.hp.hpl.jena.rdf.arp.impl.RDFXMLParser.parse(RDFXMLParser.java:151)
at com.hp.hpl.jena.rdf.arp.ARP.load(ARP.java:119)
at org.apache.jena.riot.lang.LangRDFXML.parse(LangRDFXML.java:142)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTFactoryImpl$1.read(RDFParserRegistry.java:142)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:760)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:258)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:244)
at org.apache.jena.riot.adapters.RDFReaderRIOT.read(RDFReaderRIOT.java:69)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:274)
at GenerateRDF.setRDF(GenerateRDF.java:59)
at PersonalInfo$2.actionPerformed(PersonalInfo.java:251)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Is there a way to fix this error? I'm open to solutions...
You might want to take a look here : https://hub.docker.com/r/stain/jena-fuseki/
There is a part on data loading that can guide you.
More specifically, load.sh and tdbloader that can be found here : https://github.com/stain/jena-docker/tree/master/jena-fuseki
I'm a bit puzzled by your question as you mention "upload a file to fuseki" in the tittle but your code does not refer to any file...

Java sqlite database is locked

I am trying to delete a student from database, but I got this error:
java.sql.SQLException: database is locked
at org.sqlite.core.DB.throwex(DB.java:859)
at org.sqlite.core.DB.exec(DB.java:142)
at org.sqlite.jdbc3.JDBC3Connection.commit(JDBC3Connection.java:165)
at Controller.deleteStudent(Controller.java:232)
at Test$9.actionPerformed(Test.java:227)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I read other posts on stackoverflow and all of them said that all connections needs to be closed to open a new connection. I did this, but I still got the same problem.
Here's my code:
public static void deleteStudent(int id) {
try {
con = null;
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:test.db");
con.setAutoCommit(false);
stmt = null;
stmt = con.createStatement();
int result = stmt.executeUpdate("DELETE FROM STUDENTS WHERE ID=" + id + ";");
System.out.println(result);
con.commit();
stmt.close();
con.close();
output();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
Do you have ideas why I still get this error?

Updated in a database [update ... set] java

I have a problem with my java code. When I do a database update but they don't work up . I used the three methods that I found on the internet and still they have not worked!
Help me
thank you in advance
package HLR_SERVEUR;
public class model_HLR{
public void setupdate(String[] information)
{
int imsdn_values,cins,kcs,kis;
long IMSI_values=0;
this.IMSI_values = Long.parseLong(information[0]);
this.imsdn_values = Integer.parseInt(information[1]);
this.kis = Integer.parseInt(information[2]);
this.kcs = Integer.parseInt(information[3]);
this.service = new String(information[4]);
this.nom = new String(information[5]);
this.prenom = new String(information[6]);
this.cins = Integer.parseInt(information[7]);
System.out.println(this.IMSI_values);
System.out.println(this.imsdn_values);
System.out.println(this.kis);
System.out.println(this.kcs);
System.out.println(this.service);
System.out.println(this.nom);
System.out.println(this.prenom);
System.out.println(this.cins);
try {
Class.forName("com.mysql.jdbc.Driver");
dbConnect = DriverManager.getConnection("jdbc:mysql://localhost/abonnes", "root","");
dbStatement = dbConnect.createStatement();
/*
test 1:
PreparedStatement prepareStatement = (PreparedStatement) dbConnect.prepareStatement("Update sim set ISMIDN="+this.imsdn_values +", KI="+this.kis +",KC="+this.kcs+",SERVICE='"+this.service +"',nom='"+this.nom +"',prenom='"+this.prenom +"',cin="+this.cins +" Where IMSI="+this.IMSI_value+"");
k=prepareStatement.executeUpdate();
test 2:
PreparedStatement checkDB = (PreparedStatement) dbConnect.prepareStatement( "UPDATE sim set ISMIDN= ? ,KI= ?,KC= ?,SERVICE= ?,nom= ?,prenom= ?,cin= ? Where ISMI= ? ");
checkDB.setInt(1,this.imsdn_values);
checkDB.setInt(2,this.kis);
checkDB.setInt(3,this.kcs);
checkDB.setString(4,this.service);
checkDB.setString(5,this.nom);
checkDB.setString(6,this.prenom);
checkDB.setInt(7,this.cins);
checkDB.setLong(8,this.IMSI_values);
k=checkDB.executeUpdate();
*/
/* test 3: */
dbStatement=dbConnect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = dbStatement
.executeQuery("SELECT * FROM sim where ISMI ='"
+ this.IMSI_values + "'");
uprs.moveToInsertRow();
uprs.updateInt("ISMIDN", this.imsdn_values);
uprs.updateInt("KI", this.kis);
uprs.updateInt("KC", this.kcs);
uprs.updateString("SERVICE", this.service);
uprs.updateString("nom", this.nom);
uprs.updateString("prenom", this.prenom);
uprs.updateInt("cin", this.cins);
uprs.insertRow();
uprs.beforeFirst();
dbStatement.close();
dbConnect.close();
} catch (SQLException ex) {
Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
}
}
mai 12, 2015 12:20:55 AM HLR_SERVEUR.model_HLR setupdate
GRAVE: null
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ISMI' cannot be null
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
at com.mysql.jdbc.UpdatableResultSet.insertRow(UpdatableResultSet.java:739)
at HLR_SERVEUR.model_HLR.setupdate(model_HLR.java:304)
at HLR_SERVEUR.AbonnePanel_Rechercher.actionPerformed(AbonnePanel_Rechercher.java:401)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
problems mai 12, 2015 1:42:15 AM HLR_SERVEUR.model_HLR setupdate GRAVE: null com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '216011100258963' for key 'PRIMARY
From the log that you posted as answer, column ISMI is a mandatory field for your database table, it seems like a primary key.
You need something like:
uprs.updateInt("ISMI", someValue);
to complete your new row data.
Please also note that primary key must be unique in table.

Categories