All I want it search the related names and set value on jtextfeild, like we got in google. (Give name suggestions that you have in database). Here is the code I used but it gets syntax error. Of course it should get it. Because code is wrong.
private void txtLnameKeyReleased(java.awt.event.KeyEvent evt)
{
try {
ResultSet rs = JDBC.getData("select lot_name from lot where lot_type='" + company.getSelectedItem().toString() + "' and lot_name like '"+txtLname.getText()+"'% ");
if (rs.first()) {
txtLname.setText(rs.getString("lot_name"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
I really don't know how to set up % with text field's gettext() method. Please help me. Thank you.
Added error
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1521)
at Modle.JDBC.getData(JDBC.java:46)
at lottery.LottryRegistration.txtLnameKeyReleased(LottryRegistration.java:736)
at lottery.LottryRegistration.access$1800(LottryRegistration.java:22)
at lottery.LottryRegistration$16.keyReleased(LottryRegistration.java:298)
at java.awt.Component.processKeyEvent(Component.java:6466)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2829)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Percent on the wrong side of comment sign:
ResultSet rs = JDBC.getData("select lot_name from lot where lot_type='"
+ company.getSelectedItem().toString()
+ "' and lot_name like '"
+ txtLname.getText()
+ "%' ");
Below is the code, Spent Hour trying to track where is error...
Code is much big... more then 45 Fields so more confused
Exception is `java.lang.NullPointerException`
code is
String Scholno=getScholarNo();
ScholarNo.setText(Scholno);
addstudent = cnn.prepareStatement ("Insert into student(
ScholarNo, Student_Name, Application_No, DateOfAdmission,
Fathers_Name, Gender, DOB, Address, Session, Contact_no, Email, Course,
Branch, Submitted_Documents, Nationality, GuardianName, GuardianContactNo,
GuardianAddress, High_School_name, HS_Year_of_passing, HS_Percentage,
HS_Board, Higher_secondary_Name, H_year_of_passing, H_percentage,
H_board, Graduation, G_year_of_passing, G_percentage, G_University,
Post_graduation, PG_year_of_passing, PG_percentage, PG_university,
mother_name, religion, category, semester, section, status,Photo) ;
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
addstudent.setString(1,ScholarNo.getText());
addstudent.setString(2,StudentName.getText().trim());
addstudent.setString(3,AdmissionNo.getText().trim());
addstudent.setString(4,DateOfAdmission.getDate().toString());
addstudent.setString(5,FatherName.getText().trim());
addstudent.setString(6,Gender.getSelectedItem().toString().trim());
addstudent.setString(7, DOB.getDate().toString());
addstudent.setString(8,Address.getText().trim());
addstudent.setString(9,Session.getSelectedItem().toString());
addstudent.setString(10,ContactNo.getText().trim());
addstudent.setString(11,Email.getText().trim());
addstudent.setString(12,Course.getSelectedItem().toString().trim());
addstudent.setString(13,Branch.getSelectedItem().toString().trim());
addstudent.setString(14,DocumentSubmitted.getText().trim());
addstudent.setString(15,Nationality.getText().trim());
addstudent.setString(16,GuardianName.getText().trim());
addstudent.setString(17,GuardianContactNo.getText().trim());
addstudent.setString(18,GuardianAddress.getText().trim());
addstudent.setString(19,HS.getText().trim());
addstudent.setString(20,HSYOP.getText().trim());
addstudent.setString(21,HSPercentage.getText().trim());
addstudent.setString(22,HSBoard.getText().trim());
addstudent.setString(23,HSS.getText().trim());
addstudent.setString(24,HSSYOP.getText().trim());
addstudent.setString(25,HSSPercentage.getText().trim());
addstudent.setString(26,HSSBoard.getText().trim());
addstudent.setString(27,UG.getSelectedItem().toString().trim());
addstudent.setString(28,GYOP.getText().trim());
addstudent.setString(29,GPercentage.getText().trim());
addstudent.setString(30,GUniy.getText().trim());
addstudent.setString(31,PG.getSelectedItem().toString().trim());
addstudent.setString(32,PGYOP.getText().trim());
addstudent.setString(33,PGpercentage.getText().trim());
addstudent.setString(34,PGUniy.getText().trim());
addstudent.setString(35,MotherName.getText().trim());
addstudent.setString(36,Religion.getSelectedItem().toString().trim());
addstudent.setString(37,Category.getSelectedItem().toString().trim());
addstudent.setString(38,Semester.getSelectedItem().toString().trim());
addstudent.setString(39,Section.getSelectedItem().toString().trim());
addstudent.setString(40,Status.getSelectedItem().toString().trim());
addstudent.setBytes(41,person_image);
addstudent.executeUpdate();
} catch(Exception e) {
//e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
Result of Stack
run:
java.lang.NullPointerException
at projectmanagment.frmStudentRegistration.btnupdateActionPerformed(frmStudentRegistration.java:895)
at projectmanagment.frmStudentRegistration.btnupdateActionPerformed(frmStudentRegistration.java:895)
at projectmanagment.frmStudentRegistration.access$300(frmStudentRegistration.java:25)
at projectmanagment.frmStudentRegistration$4.actionPerformed(frmStudentRegistration.java:563)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
It got solved, error was regarding date which gave me null pointer Error, will post another Question for its answer so others are also benifited having same trouble
My query :
SELECT COUNT(*)
FROM
(SELECT
dealerCode,
SUM(kg) AS totalKG,
SUM(price) AS totalPrice,
returnDate, BID
FROM meatReturns
GROUP BY BID, dealerCode, returnDate)
This works well in MS Access Query Design, but it does not work in JDBC.
The query gets a Syntax error in FROM clause in its ResultSet.
Any alternatives, or an explanation to this one?
UPDATE:
Here is my code:
private int getRowCount(String query){
int size = 0;
try {
query = query.replace(";", "");
query = "SELECT COUNT(*) FROM (" + query +") AS subQuery;";
System.out.println(query);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String db = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/EACA_AgroVentures1.accdb";
conn = DriverManager.getConnection(db);
stmt = conn.prepareStatement(query,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(); // ERROR HERE
rs.beforeFirst();
while(rs.next() && rs!=null){
size = rs.getInt(1);
System.out.println("Size : "+size);
}
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
return size;
}
and here is the ERROR CODE:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3117)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:252)
at sun.jdbc.odbc.JdbcOdbcResultSet.calculateRowCount(JdbcOdbcResultSet.java:6352)
at sun.jdbc.odbc.JdbcOdbcResultSet.initialize(JdbcOdbcResultSet.java:154)
at sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(JdbcOdbcStatement.java:423)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPreparedStatement.java:92)
at com.eaca.MainFrame.getRowCount(MainFrame.java:139)
at com.eaca.MainFrame.connectToDBWithRows(MainFrame.java:171)
at com.eaca.MainFrame.loadMR(MainFrame.java:350)
at com.eaca.MainFrame.access$600(MainFrame.java:65)
at com.eaca.MainFrame$ChangeTab.stateChanged(MainFrame.java:486)
at javax.swing.JTabbedPane.fireStateChanged(JTabbedPane.java:416)
at javax.swing.JTabbedPane$ModelListener.stateChanged(JTabbedPane.java:270)
at javax.swing.DefaultSingleSelectionModel.fireStateChanged(DefaultSingleSelectionModel.java:132)
at javax.swing.DefaultSingleSelectionModel.setSelectedIndex(DefaultSingleSelectionModel.java:67)
at javax.swing.JTabbedPane.setSelectedIndexImpl(JTabbedPane.java:616)
at javax.swing.JTabbedPane.setSelectedIndex(JTabbedPane.java:591)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(BasicTabbedPaneUI.java:3644)
at java.awt.Component.processMouseEvent(Component.java:6502)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at com.eaca.MainFrame.connectToDBWithRows(MainFrame.java:185)
at com.eaca.MainFrame.loadMR(MainFrame.java:350)
at com.eaca.MainFrame.access$600(MainFrame.java:65)
at com.eaca.MainFrame$ChangeTab.stateChanged(MainFrame.java:486)
at javax.swing.JTabbedPane.fireStateChanged(JTabbedPane.java:416)
at javax.swing.JTabbedPane$ModelListener.stateChanged(JTabbedPane.java:270)
at javax.swing.DefaultSingleSelectionModel.fireStateChanged(DefaultSingleSelectionModel.java:132)
at javax.swing.DefaultSingleSelectionModel.setSelectedIndex(DefaultSingleSelectionModel.java:67)
at javax.swing.JTabbedPane.setSelectedIndexImpl(JTabbedPane.java:616)
at javax.swing.JTabbedPane.setSelectedIndex(JTabbedPane.java:591)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(BasicTabbedPaneUI.java:3644)
at java.awt.Component.processMouseEvent(Component.java:6502)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Your problem stems from the fact that
the subquery is an aggregation query (with SUM() functions and a GROUP BY clause) so the result set returned by the Access Database Engine is not updatable, and
in your prepareStatement call you specify ResultSet.TYPE_SCROLL_SENSITIVE.
Those conditions conflict with each other, causing an error. Try this instead:
stmt = conn.prepareStatement(query,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery();
// rs.beforeFirst(); // (disabled)
I'm trying to run my simple java-program, but have a big problem.
It's connected with GUI. It can not show any created window. I attach stack-trace and one class.
#ConvertAsProperties(
dtd = "-//org.shop.viewer//ShopViewer//EN",
autostore = false
)
#TopComponent.Description(
preferredID = "ShopViewerTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
#TopComponent.Registration(mode = "explorer", openAtStartup = false)
#ActionID(category = "Window", id = "org.shop.viewer.ShopViewerTopComponent")
#ActionReference(path = "Menu/Window" /*, position = 333 */)
#TopComponent.OpenActionRegistration(
displayName = "#CTL_ShopViewerAction",
preferredID = "ShopViewerTopComponent"
)
#Messages({
"CTL_ShopViewerAction=ShopViewer",
"CTL_ShopViewerTopComponent=ShopViewer Window",
"HINT_ShopViewerTopComponent=This is a ShopViewer window"
})
public final class ShopViewerTopComponent extends TopComponent {
public ShopViewerTopComponent() {
initComponents();
setName(Bundle.CTL_ShopViewerTopComponent());
setToolTipText(Bundle.HINT_ShopViewerTopComponent());
EntityManager entityManager = Persistence.createEntityManagerFactory("ShopLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("Shops.findAll");
List<Shops> resultList = query.getResultList();
for (Shops c : resultList) {
jTextArea1.append(c.getTitle() +"dqwdqwdqwdqwd"+ "\n");
}
}
java.lang.IllegalStateException: Cannot find TopComponent with preferredID ShopViewerTopComponent, see IDE log for more details.
at org.openide.windows.OpenComponentAction.actionPerformed(OpenComponentAction.java:91)
at org.openide.awt.AlwaysEnabledAction$1.run(AlwaysEnabledAction.java:198)
at org.openide.util.actions.ActionInvoker$1.run(ActionInvoker.java:95)
at org.openide.util.actions.ActionInvoker.doPerformAction(ActionInvoker.java:116)
at org.openide.util.actions.ActionInvoker.invokeAction(ActionInvoker.java:99)
at org.openide.awt.AlwaysEnabledAction.actionPerformed(AlwaysEnabledAction.java:201)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I think that a misstake is in TopComponent-constructor.
Thanks a lot.
This problem "cannot find TopCoponent with preferredID..." happens frequently when a problem occurs before loading the TopComponent.
A simple example : you try to load something in the constructor that fails (at any depth).
This unexplicit message made me mad more than once !
Hope this helps.
My Why this exception occur?
public String setIDAndInsert(String fName, String lName, String gender, String date) {
String id = null;
ResultSet res;
try {
Connection con;
PreparedStatement pStatement;
String query = "insert into Users(FirstName,LastName,Gender,Date) " +
"values ( '" + fName + "' , '" + lName + "' , '" + gender + "', '" + date + "' ) ";
con = DriverManager.getConnection(...);
pStatement = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
pStatement.execute(query);
res = pStatement.getGeneratedKeys();
while (res.next()) {
id = String.valueOf(res.getInt(1));
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
return id;
}
Previously this method works correctly, I don't know why now hasn't work!
My table in console:
java.sql.SQLException: Failed to read auto-increment value from storage engine
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:734)
at Project.UserPage_Admin.setIDAndInsert(UserPage_Admin.java:145)
at Project.UserPage_Admin.addAction(UserPage_Admin.java:127)
at Project.UserPage_Admin.actionPerformed(UserPage_Admin.java:114)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Try this:
ALTER TABLE `table_name` AUTO_INCREMENT = 1