
正文
java小程序代码新程序 java小程序代码新程序怎么用
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
谁能给个JAVA的小程序代码,越小越好!
这是我晓得的最简单的java小程序代码了你可以看看:
package com.kenki.emp;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;
import java.sql.*;
public class emp extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String code = request.getParameter("code");
String name = request.getParameter("name");
String pay = request.getParameter("pay");
System.out.println("empcode:" + code);
System.out.println("name:" + name);
System.out.println("pay:" + pay);
//创建驱动
new com.microsoft.jdbc.sqlserver.SQLServerDriver();
String strd =
"jdbc:microsoft:sqlserver://localhost:1433;databasename=emp_dates";
String username = "sa";
String pws = "";
try {
java.sql.Connection conn = java.sql.DriverManager.getConnection(
strd, username, pws);
String strs = "insert into emp values(?,?,?)";
java.sql.PreparedStatement pre = conn.prepareStatement(strs);
pre.setString(1, code);
pre.setString(2, name);
pre.setString(3, pay);
pre.execute();
pre.close();
conn.close();
//重定向至查询页面
out.println("成功保存!!");
response.sendRedirect("emp.html");
} catch (SQLException ss) {
ss.printStackTrace();
response.sendRedirect("/WebModule1/error.html");
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
相关问答
Q1: 编写一个java小程序!
public test_03(){
init();
}
public void init(){
JLabel jl_1=new JLabel("用户名");
JLabel jl_2=new JLabel("密码");
JTextField jtf=new JTextField();
JPasswordField jpf=new JPasswordField();
JButton button_1=new JButton("确定");
JPanel panel=new JPanel();
panel.setLayout(null);
jl_1.setBounds(30, 50, 50, 30);
jl_2.setBounds(30,90,50,30);
jtf.setBounds(100, 50, 100, 30);
jpf.setBounds(100, 90, 100, 30);
button_1.setBounds(110, 130, 80, 30);
panel.add(jl_1);
panel.add(jl_2);
panel.add(jtf);
panel.add(jpf);
panel.add(button_1);
this.add(panel);
this.setSize(300, 250);
this.setLocation(400, 300);
this.setVisible(true);
}
public static void main(String[] args) {
new test_03();
}
Q2: java一个简单小程序,求高手帮忙编写,万分感谢
class Ball {
public void play() {
System.out.println("玩球儿...");
}
}
class Football extends Ball {
public void play() {
System.out.println("使用足球运动");
}
}
class Basketball extends Ball {
public void play() {
System.out.println("使用篮球运动");
}
}
public class TestMain {
public static void main(String[] args) {
TestMain tm = new TestMain();
tm.testPlay();
}
public void testPlay() {
Ball ball = new Football();
ball.play();
ball = new Basketball();
ball.play();
}
}
/*
D:\javac TestMain.java
D:\java TestMain
使用足球运动
使用篮球运动
*/
java小程序代码新程序的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java小程序代码新程序怎么用、java小程序代码新程序的信息别忘了在本站进行查找喔。








