Java Netbeans GUI和SQL问题
//我对Netbeans有问题。当我单击register时,我试图将我在注册表中输入的值转到sql表,但什么都没有发生。有人能帮忙吗Java Netbeans GUI和SQL问题,java,sql,user-interface,netbeans,project,Java,Sql,User Interface,Netbeans,Project,//我对Netbeans有问题。当我单击register时,我试图将我在注册表中输入的值转到sql表,但什么都没有发生。有人能帮忙吗 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package networking; import java.sql.Connection; import java.sql.DriverManager; imp
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package networking;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
/**
*
* @author user
*/
public class Registration extends javax.swing.JFrame {
/**
* Creates new form Registration
*/
public Registration() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
FullNameField = new javax.swing.JTextField();
EmailField = new javax.swing.JTextField();
Username = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
AdressField = new javax.swing.JTextArea();
PasswordField = new javax.swing.JPasswordField();
Registeration = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Registration Form ");
jLabel2.setText("Full Name");
jLabel3.setText("Email");
jLabel4.setText("Username");
jLabel5.setText("Password");
jLabel6.setText("Adresse");
FullNameField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FullNameFieldActionPerformed(evt);
}
});
AdressField.setColumns(20);
AdressField.setRows(5);
jScrollPane1.setViewportView(AdressField);
Registeration.setText("Register");
Registeration.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RegisterationActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(105, 105, 105)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(Registeration)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(PasswordField)
.addComponent(Username)
.addComponent(EmailField)
.addComponent(FullNameField)
.addComponent(jScrollPane1)))))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(105, 282, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(FullNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(EmailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(Username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel6)))
.addGap(18, 18, 18)
.addComponent(Registeration)
.addContainerGap(27, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void RegisterationActionPerformed(java.awt.event.ActionEvent evt) {
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/networks","root","mamaendbaba");
Statement stat = (Statement) con.createStatement();
String Name = FullNameField.getText();
String UserName= Username.getText();
String Adr = AdressField.getText();
String Pass = PasswordField.getText();
String Emai = EmailField.getText();
String excmd = "INSERT INTO networks registerd(Name, UserName, Address, Password, Email)" +
" VALUES (?, ?, ?, ?, ?)";
@SuppressWarnings("UnusedAssignment")
PreparedStatement statement =con.prepareStatement(excmd);
statement = (PreparedStatement) con.createStatement();
// get field values ...
statement.setString(1, Name);
statement.setString(2, UserName);
statement.setString(3, Adr);
statement.setString(4, Pass);
statement.setString(5, Emai);
statement.executeUpdate();
}
catch(Exception e)
{
}
}
private void FullNameFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Registration().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextArea AdressField;
private javax.swing.JTextField EmailField;
private javax.swing.JTextField FullNameField;
private javax.swing.JPasswordField PasswordField;
private javax.swing.JButton Registeration;
private javax.swing.JTextField Username;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}
/*
*要更改此模板,请选择工具|模板
*然后在编辑器中打开模板。
*/
包联网;
导入java.sql.Connection;
导入java.sql.DriverManager;
导入java.sql.PreparedStatement;
导入java.sql.Statement;
/**
*
*@author用户
*/
公共类注册扩展了javax.swing.JFrame{
/**
*创建新的表单注册
*/
公开注册(){
初始化组件();
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
//
私有组件(){
jLabel1=newjavax.swing.JLabel();
jLabel2=newjavax.swing.JLabel();
jLabel3=newjavax.swing.JLabel();
jLabel4=newjavax.swing.JLabel();
jLabel5=newjavax.swing.JLabel();
jLabel6=newjavax.swing.JLabel();
FullNameField=newjavax.swing.JTextField();
EmailField=newjavax.swing.JTextField();
Username=newjavax.swing.JTextField();
jScrollPane1=newjavax.swing.JScrollPane();
addressfield=newjavax.swing.JTextArea();
PasswordField=newjavax.swing.JPasswordField();
registation=newjavax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText(“登记表”);
jLabel2.setText(“全名”);
jLabel3.setText(“电子邮件”);
jLabel4.setText(“用户名”);
jLabel5.setText(“密码”);
jLabel6.setText(“地址”);
FullNameField.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
FullNameFieldActionPerformed(evt);
}
});
地址字段。设置列(20);
地址字段。设置行(5);
jScrollPane1.setViewportView(地址字段);
registration.setText(“寄存器”);
Registration.addActionListener(新的java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的注册操作(evt);
}
});
javax.swing.GroupLayout=newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(布局);
layout.setHorizontalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(105、105、105)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.training)
.addComponent(注册)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2,javax.swing.GroupLayout.PREFERRED\u SIZE,64,javax.swing.GroupLayout.PREFERRED\u SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.training,false)
.addComponent(jLabel3、javax.swing.GroupLayout.Alignment.LEADING、javax.swing.GroupLayout.DEFAULT\u SIZE、javax.swing.GroupLayout.DEFAULT\u SIZE、Short.MAX\u值)
.addComponent(jLabel4、javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5、javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6,javax.swing.GroupLayout.Alignment.LEADING,javax.swing.GroupLayout.DEFAULT\u SIZE,javax.swing.GroupLayout.DEFAULT\u SIZE,Short.MAX\u VALUE)))
.addGap(18,18,18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,false)
.addComponent(密码字段)
.addComponent(用户名)
.addComponent(电子邮件字段)
.addComponent(全名字段)
.addComponent(jScrollPane1()()))
.addGroup(layout.createSequentialGroup()
.addGap(21,21,21)
.addComponent(jLabel1,javax.swing.GroupLayout.PREFERRED_SIZE,131,javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(105282,短。最大值))
);
layout.setVerticalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26,26,26)
.addComponent(jLabel1,javax.swing.GroupLayout.PREFERRED\u SIZE,29,javax.swing.GroupLayout.PREFERRED\u SIZE)
.addGap(28,28,28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(FullNameField、javax.swing.GroupLayout.PREFERRED\u SIZE、javax.swing.GroupLayout.DEFAULT\u SIZE、javax.swing.GroupLayout.PREFERRED\u SIZE))
.addGap(18,18,18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(EmailField,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAU
String excmd = "INSERT INTO networks registerd VALUES ('" + Name + "','"+ UserName +"','"+ Adr +"','"+ Pass +"','"+ Emai +"')";
e.printStackTrace();
String excmd =
"INSERT INTO registerd(Name, UserName, Address, Password, Email)" +
" VALUES (?, ?, ?, ?, ?)";
PreparedStatement statement = con.createPreparedStatement(excmd);
// get field values ...
statement.setString(1, Name);
statement.setString(2, UserName);
statement.setString(3, Adr);
statement.setString(4, Pass);
statement.setString(5, Emai);
statement.executeUpdate();