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.
Related
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.
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);
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?
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.
Method where im getting an error on:
public ArrayList<Log> selectAllLogs(){
if(openConn()){
ArrayList<Log> list = new ArrayList<Log>();
Boolean doesLogExists = false;
String query = "SELECT * FROM logs a LEFT JOIN log_lines s on a.log_id = s.log_id";
try{
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
Log log = null;
while(rs.next()){
for (Log l : list) {
if(l.getLogId() == rs.getInt("log_id")){
log = l;
doesLogExists = true;
System.out.println("check");
}
}
if(doesLogExists){
log.getLogLines().add(rs.getString("log_lines"));
Iterator<Log> iter = list.iterator();
int i = 0;
System.out.println("true");
while(iter.hasNext()){
if(iter.next().getLogId() == ((list.get(i).getLogId()))){
list.remove(i);
list.add(i, log);
break;
}
i++;
}
doesLogExists = false;
} else {
System.out.println("false");
log = new Log();
log.setDateName(rs.getString("log_name"));
log.setLogId(rs.getInt("log_id"));
log.getLogLines().add(rs.getString("log_lines"));
list.add(log);
}
}
}
catch(SQLException sqle){
sqle.printStackTrace();
}
try {
closeConn();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
try {
closeConn();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Stackstrace:
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:804)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:852)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5773)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5693)
at DataLayer.DatabaseConnector.selectAllLogs(DatabaseConnector.java:313)
at model.LogContainer.<init>(LogContainer.java:15)
at model.LogContainer.getInstance(LogContainer.java:20)
at view.LogOverview.initGui(LogOverview.java:91)
at view.LogOverview.<init>(LogOverview.java:27)
at controller.MainFrameController.actionPerformed(MainFrameController.java:65)
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$200(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)
Im getting an error on this piece of code, it is out of the else part in the while loop.
list.add(log);
I have googled the exception but i don't understand it. Can someone help me?
You can see from the stacktrace that the statement where the exception occurs in the method selectAllLogs is actually the call to com.mysql.jdbc.ResultSetImpl.getString, and not the statement list.add(log); There's an off by one error in where you thought the exception was occuring.
The reason that you're getting the SQLException is probably because you're not closing the ResultSet. This question is about the same issue.