我是一名新手程序员,从事涉及MySQL,Netbeans和Wamp的项目。我试图将输入GUI的某些行链接到我的数据库,但它始终以我们的方式抛出错误。老师甚至通过代码找到无效的解决方案,所以我想请你们中的一些人看看你是否能帮我发现错误。代码如下:
private void btn_processOrderActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if( check_addressNew.isSelected()==true) {
Shipping add = new Shipping();
add.setAddress1(txt_deliveryAddress1.getText());
add.setAddress2(txt_deliveryAddress2.getText());
add.getState(txt_deliveryState.getText());
add.setSuburb (txt_deliverySuburb.getText());
add.setPostcode (txt_deliveryPostcode.getText());
ModernGlassConnection myConnection = new ModernGlassConnection();
myConnection.setShipping(add);
}
}
以下是Setters and Getters
package Modern_Glass;
/**
*
* @author
*/
public class Shipping {
private String address1;
private String address2;
private String states;
private String suburb;
private String postcode;
/**
* @return the address1
*/
public String getAddress1() {
return address1;
}
/**
* @param address1 the address1 to set
*/
public void setAddress1(String address1) {
this.address1 = address1;
}
/**
* @return the address2
*/
public String getAddress2() {
return address2;
}
/**
* @param address2 the address2 to set
*/
public void setAddress2(String address2) {
this.address2 = address2;
}
/**
* @return the state
*/
public String getState() {
return states;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.states = state;
}
/**
* @return the suburb
*/
public String getSuburb() {
return suburb;
}
/**
* @param suburb the suburb to set
*/
public void setSuburb(String suburb) {
this.suburb = suburb;
}
/**
* @return the postcode
*/
public String getPostcode() {
return postcode;
}
/**
* @param postcode the postcode to set
*/
public void setPostcode(String postcode) {
this.postcode = postcode;
}
void getState(String text) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
然后是连接代码
package Modern_Glass;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ModernGlassConnection {
// ****** START DATABASE CONNECTION ****** //
public Connection connection = null;
public Connection getConnection() {
try {
System.out.println("---------MySQL Connection Testing---------");
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Can't find MySQL Driver");
return null;
// e.printStackTrace();
}
System.out.println("My Driver Registered");
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/modernglass","root","");
return connection;
} catch (SQLException e) {
System.out.println("Connection fail!!!");
}
if (connection != null) {
System.out.println("Connection Success!!!");
} else {
System.out.println("Connection fail - check your database server!!!");
}
return connection ;
} // ****** END DAT ABASE CONNECTION ****** //
public void setShipping(Shipping address) {
String insertDate =
"INSERT INTO Orders (deliveryAddress1, deliveryAddress2, deliveryState, deliverySuburb, deliveryPostcode) " +
"VALUES ( ? , ? , ? , ? , ? )";
Connection connection = getConnection();
System.out.println("Connection established");
try {
PreparedStatement ps = connection.prepareStatement(insertDate);
String ad1 = address.getAddress1();
String ad2 = address.getAddress2();
String ad3 = address.getState();
String ad4 = address.getSuburb();
String ad5 = address.getPostcode();
ps.setString(1, address.getAddress1());
ps.setString(2, address.getAddress2());
ps.setString(3, address.getState());
ps.setString(4, address.getSuburb());
// int postcode = Integer.parseInt(address.getPostcode());
//ps.setString(5,address.getPostcode() );
int rs = ps.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(ModernGlassConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
它吐出的错误是:
Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
at Modern_Glass.Shipping.getState(Shipping.java:91)
at Modern_Glass.Modern_Glass_GUI_Delivery_Details.btn_processOrderActionPerformed(Modern_Glass_GUI_Delivery_Details.java:218)
at Modern_Glass.Modern_Glass_GUI_Delivery_Details.access$200(Modern_Glass_GUI_Delivery_Details.java:13)
at Modern_Glass.Modern_Glass_GUI_Delivery_Details$3.actionPerformed(Modern_Glass_GUI_Delivery_Details.java:127)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
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:6527)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6292)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4883)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
提前谢谢 -
答案 0 :(得分:0)
private void btn_processOrderActionPerformed(java.awt.event.ActionEvent evt)
呼叫
add.getState(txt_deliveryState.getText());
执行
throw new UnsupportedOperationException("Not supported yet.");
完全抛出的异常。 (堆栈跟踪中的第二行应该恰好是该行)
我认为就是那个
add.getState(txt_deliveryState.getText());
应改为
add.setState(txt_deliveryState.getText());
并且吸气剂并不意味着有一个参与者,我想。
BTW:您可以从堆栈跟踪中获取该信息。只需看看第一行,即您的某个课程。这有助于大多数情况。 Netbeans甚至应该在代码行之外创建一个链接。 (在这种情况下为(Shipping.java:91)
)。只需单击该链接,NetBeans就应该直接跳到该行。