申报信息表代码java 申报结果代码( 二 )


}
}
利用java代码,编写JDBC连接数据库新增员工信息的步骤. 员工信息表:t_emp(id int?第一步:新建数据库
连接的是本地localhost,新建一个新的数据库名是jdbctest
然后建表t_emp
不会的话可通过执行下方的sql语句建表
CREATE TABLE `t_emp` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`salary` double DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
第二步:新建java项目
新建完以后添加mysql驱动的jar包,jar包自己下载
在项目上右键鼠标属性,然后
添加jar包,我这里已经加载过了
第三步:编写代码
package com.gf;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class Test {
public static void main(String[] args) throws Exception {
int flag=0;
//1.加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2.获取连接
Connection conn=(Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jdbctest?user=rootpassword=123456useUnicode=truecharacterEncoding=UTF-8");
//3.创建statement
Statement sm=(Statement) conn.createStatement();
//4.执行sql语句
flag=sm.executeUpdate("insert into t_emp(name,salary) values('菲菲',34.9)");
if(flag!=0) {
System.out.println("员工信息增加成功");
}else {
System.out.println("添加失败");
}
}
}
注意点:
---------------------------------------------------------------------------------
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jdbctest?user=rootpassword=123456useUnicode=truecharacterEncoding=UTF-8");
这里需要修改自己本机的连接信息,不然会出现连接失败
最后的执行结果
简单个人简历java录入程序 代码我帮你写了那些JAVA代码了,效果包你满意!呵呵……
至于网页的代码嘛,这里就不贴了 。你要的话HI我吧^_^ 。
JAVA代码如下:
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Rectangle;
public class MyLuRu extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JTextField jTextField = null;
private JRadioButton jRadioButton = null;
private JRadioButton jRadioButton1 = null;
private JComboBox jComboBox = null;
private JComboBox jComboBox1 = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JTextArea jTextArea = null;
private ButtonGroup mybg=new ButtonGroup();
/**
* This is the default constructor
*/
public MyLuRu() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(268, 407);
this.setContentPane(getJContentPane());
this.setTitle("录入");
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(16, 150, 65, 18));
jLabel3.setText("文化程度:");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(16, 108, 39, 18));

推荐阅读