java版系统源码
用户登录数据库代码示例如下:
首先导入必要的Java sql包:
import java.sql.*;
定义一个名为Database的类:
class Database {
在该类中初始化连接、结果集和语句对象:
Connection con; ResultSet rs; Statement stmt;
构造方法中进行数据库连接:
public Database() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbcdbc:HDB"; con = DriverManager.getConnection(url); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (Exception ex) { System.out.println(ex); } }
根据用户名获取密码的方法:
public String getPswd(String name) { try { rs = stmt.executeQuery("SELECT pswd FROM User WHERE Name = '" + name + "'"); rs.last(); if (rs.getRow() == 0) { return null; } else { String pswdDB = rs.getString("Pswd"); return pswdDB; } } catch (Exception e) { System.out.println(e); return null; } }
向用户表中插入新数据的方法:
public boolean insertData(String name, String pswd) { try { String s = getPswd(name); if (s == null) { int rtn = stmt.executeUpdate("INSERT INTO User VALUES('" + name + "','" + pswd + "')"); if (rtn != 0) return true; } else { return false; } return false; } catch (Exception et) { System.out.println(et); return false; } }
图书数据库代码示例:
class BookDatabase {
同样初始化连接、结果集和语句对象:
Connection con; ResultSet rs; Statement stmt;
构造方法中进行数据库连接:
public BookDatabase() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbcdbc:Book"; con = DriverManager.getConnection(url); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (Exception ex) { System.out.println(ex); } }
插入图书信息的方法:
public boolean insertData(String id, String name, String where, String price, String date) { try { int rtn = stmt.executeUpdate("INSERT INTO Book VALUES('" + id + "','" + name + "','" + where + "','" + price + "','" + date + "')"); if (rtn != 0) { return true; } else { return false; } } catch (Exception et) { System.out.println(et); return false; } }
此代码段主要用于图书借阅系统的数据库操作,包括用户登录验证和图书信息管理。
请注意,这里展示的代码使用了JDBC-ODBC桥驱动程序,这在现代开发中已经很少使用,建议使用JDBC驱动直接连接数据库。
‘贰’ 跪求JAVA编写的停车场管理系统源代码
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
/*********************************
* 停车场管理
* author zhang
*2013-12-13
********************************/
public class CarStopManager {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请入车牌号:");
String carno = sc.next();
CarStopManager carStopManager = new CarStopManager();
carStopManager.setCarNo(carno);//设置车牌号
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sdate = format.format(new Date());
System.out.println("当前时间(入场时间)是: "+sdate);
System.out.println("需要开出车场吗?yes/no:");
String yesno = sc.next();
if(yesno.equals("yes")){
String edate = format.format(new Date());
System.out.println("出场时间是: "+edate);
//计算方法
carManager(2, sdate, edate,carStopManager);
}
}
/**
* 计算方法
*/
public static void carManager(int type,String starTime,
String endTime,CarStopManager carStopManager){
if(type==1){//按月收费
System.out.println("如若没有缴纳月费请缴纳800元,如若缴纳将不再提示!");
}else{
/**
* 一般不会有停车几个月的吧?先不考虑停车几年或者几个月的
*/
String sDay = starTime.substring(8,10);//入场日期(天)
String sHour = starTime.substring(11, 13);//入场小时
String sMM = starTime.substring(14,16);//入场分钟
String eDay = starTime.substring(8,10);//出场日期(天)
String eHour = endTime.substring(11, 13);//出厂小时
String eMM = endTime.substring(14,16);//出厂分钟
float money = 0;//需缴纳的费用
int shour = Integer.parseInt(sHour);
int ehour = Integer.parseInt(eHour);
int smm = Integer.parseInt(sMM);
int emm = Integer.parseInt(eMM);
int rehour = 0;//停车几个小时
if(sDay.equals(eDay)){//同一天
//当天6点到20点之间
if((shour>=6 && shour<=20)){
if(ehour - shour<=6){//6个小时之内
rehour = (ehour - shour)*60+(emm - smm);//停车多少分钟
//需要缴纳的费用 前15分钟免费 以后每15分钟1.5元
money = (rehour/15-15)*1.5f;
}else{
int hour = ehour - shour -6;//6小时除外剩余小时数
rehour = 6*60+(emm - smm);//停车多少分钟
//前15分钟免费 以后每15分钟1.5元 超过6小时15分钟2元
money = ((rehour/15-15)*1.5f)+(hour*60/2);
}
}
}else{//跨天 20点到 6点之间
//todo
}
System.out.println("您的车牌号是:"+carStopManager.getCarNo()+";\n" +
"您此次停车花费的费用是: "+money+"元");
}
}
/**
* bean属性
*/
private String carNo;//车牌号
private String startTime;//入场时间
private String endTime;//出场时间
/**
* 无参构造
*/
public CarStopManager(){
super();
}
/**
* 有参数构造
* @param carNo
* @param startTime
* @param endTime
*/
public CarStopManager(String carNo, String startTime, String endTime) {
super();
this.carNo = carNo;
this.startTime = startTime;
this.endTime = endTime;
}
/**
* 设置get方法
* @return
*/
public String getCarNo() {
return carNo;
}
/**
* 设置set方法
* @param carNo
*/
public void setCarNo(String carNo) {
this.carNo = carNo;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}
‘叁’ java如何查看源码
不会就别那么肯定的说看不到~
jdk里有个src.zip,解压以后放在jre里ok
如果不行,在eclipse里建立一个叫jre的文件夹,然后把jre6里的东西考进去,把src考进去,必须行。
‘肆’ 急求一段简单的java源代码(用户名、密码操作界面)
下面的程序可以直接通过编译运行,自己寻找要用到的代码段。
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class UserLogin extends JPanel implements ActionListener{
JTextField userjt=null;//用户输入框
JPasswordField pwdjt=null;
JTextField sysUserjt=null;//系统显示用户名输入框
JTextField sysPwdjt=null;
public UserLogin(){
super(new GridLayout(1,2));
JPanel userPanel=new JPanel();//用户界面,左边
userPanel.setLayout(new BoxLayout(userPanel,BoxLayout.Y_AXIS));
this.add(userPanel);
JPanel userUpPanel=new JPanel();//用户界面上半部分
userPanel.add(userUpPanel);
JPanel userDownPanel=new JPanel();//用户界面下半部分
userPanel.add(userDownPanel);
JPanel sysPanel=new JPanel();//系统界面,右边
sysPanel.setLayout(new BoxLayout(sysPanel,BoxLayout.Y_AXIS));
this.add(sysPanel);
JPanel sysUserPanel=new JPanel();//系统界面上半部分
sysPanel.add(sysUserPanel);
JPanel sysPwdPanel=new JPanel();//系统界面下半部分
sysPanel.add(sysPwdPanel);
userjt=new JTextField(5);
userjt.setText("用户名");
userUpPanel.add(userjt);
pwdjt=new JPasswordField(5);
pwdjt.setText("密码");
pwdjt.setEchoChar('\0');
userDownPanel.add(pwdjt);
JLabel sysUserjl=new JLabel("用户名为:");
sysUserPanel.add(sysUserjl);
sysUserjt=new JTextField(5);
sysUserPanel.add(sysUserjt);
JLabel sysPwdjl=new JLabel("密码为:");
sysPwdPanel.add(sysPwdjl);
sysPwdjt=new JTextField(5);
sysPwdPanel.add(sysPwdjt);
userjt.addActionListener(this);
pwdjt.addActionListener(this);
userjt.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
if(userjt.getText().equals("用户名"))
userjt.setText("");
}
public void focusLost(FocusEvent e) {
if(userjt.getText().equals(""))
userjt.setText("用户名");
}});
pwdjt.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
if(new String(pwdjt.getPassword()).equals("密码")){
pwdjt.setText("");
pwdjt.setEchoChar('*');
}
}
public void focusLost(FocusEvent e) {
if(new String(pwdjt.getPassword()).equals("")){
pwdjt.setText("密码");
pwdjt.setEchoChar('\0');
}
}});
}
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(userjt)){
pwdjt.requestFocus();
}else{
if(new String(pwdjt.getPassword()).equals("")||userjt.getText().equals("")||userjt.getText().equals("用户名")) return;
sysUserjt.setText(userjt.getText());
sysPwdjt.setText(new String(pwdjt.getPassword()));
try {
writetoFile();
} catch (IOException e1) {
System.out.println("写入文件发生异常!");
e1.printStackTrace();
}
}
}
private void writetoFile() throws IOException{
File f=new File("User_Psd.txt");
// if(!f.exists()) f.createNewFile();
RandomAccessFile accessFile=new RandomAccessFile(f, "rw");
accessFile.seek(accessFile.length());
accessFile.write(("user:"+userjt.getText()+"\r\npassword:"+new String(pwdjt.getPassword())+"\r\n\r\n").getBytes());
}
public static void main(String args[]){
JFrame jf=new JFrame("用户登陆模块测试");
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
jf.add(new UserLogin());
jf.setBounds(400,300,280,150);
jf.setVisible(true);
}
}
‘伍’ 什么是java源代码 怎么查看
不知道你说的是浏览器的还是什么的,
如果是浏览器的那么简单找到工具-查看源代码,你就能看见代码了,
还有一个就是被编译成class文件的java用反编译工具可以看到源代码,
如果以上都不是你想要的答案,那么你所说的代码就是程序员写好的代码文件
‘陆’ java瀛︾敓鎴愮哗绠$悊绯荤粺
Java瀛︾敓鎴愮哗绠$悊绯荤粺婧愪唬镰侊细
import Java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
/*
* Created on 2005-1-11
*/
/**
* @author 璁╃倻
* @since 1.0
*
* TODO 瀛︾敓鎴愮哗娌荤悊绯荤粺
* 阃氲繃瀛﹀彿镆ユ垒,淇鏀,鍒犻櫎鏁版嵁
*
*/
public class LittleProgram
{
static boolean isDelete = true;
static boolean isFind = true;
public static void main(String [] args)//涓绘柟娉,绋嫔簭浠庤繖閲屽紑濮嬭繍琛
throws IOException,NumberNotFoundException
{
int choice=-1;
do{
LittleProgram lp = new LittleProgram();
System.out.println();
System.out.println("\t####################################");
System.out.println();
System.out.println("\t\t Java瀛︾敓鎴愮哗娌荤悊绯荤粺1.1");
System.out.println("\t\t璇风敤瀛﹀彿镆ユ垒,淇鏀,鍒犻櫎鏁版嵁");
System.out.println();
System.out.println("\t####################################\n");
System.out.print("1.澧炲姞鏁版嵁:\n"+
"2.镆ユ垒鏁版嵁:\n"+
"3.鍒犻櫎鏁版嵁:\n"+
"4.娓呴櫎镓链夋暟鎹:\n"+
"5.鎶婃暟鎹鍏ㄩ儴镓揿嵃鍒板睆骞\n"+
"6.鎶婃垚缁╂寜瀛﹀彿鎺掑簭\n"+
"7.淇鏀规暟鎹\n"+
"8.缁熻″凡璁板綍鎴愮哗瀛︾敓鏁\n"+
"9.鍏充簬浣滆\n"+
"0.阃鍑虹▼搴.\n" +
"杈揿叆:");
BufferedReader in = //浠庣粓
new BufferedReader( //绔鎺
new InputStreamReader(System.in));//鏀舵暟
String inputLine = in.readLine(); //瀛楅
choice= Integer.valueOf(inputLine).intValue();//椤;
switch(choice)
{
case 1: {//1.澧炲姞鏁版嵁
String str = lp.inputData();
lp.addData(str);
System.out.println("澧炲姞鏁版嵁鎴愬姛.");
timeOut(1);
}break;
case 2: {//2.镆ユ垒鏁版嵁
long find = 0;
璧勬枡寮旷敤:http://www.knowsky.com/363450.html
‘柒’ 急求java学生信息管理系统源代码,带有连接数据库的,万分感谢
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip = null;
SelectPanel sp = null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu("系统");
JMenu m2 = new JMenu("基本信息");
JMenu m3 = new JMenu("成绩");
JMenu m4 = new JMenu("奖惩");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11 = new JMenuItem("退出系统");
jm21 = new JMenuItem("输入");
jm22 = new JMenuItem("查询");
jm23 = new JMenuItem("更改");
jm31 = new JMenuItem("输入成绩");
jm32 = new JMenuItem("查询成绩");
jm41 = new JMenuItem("奖励");
jm42 = new JMenuItem("处分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1 = new ImageIcon();
Icon i2 = new ImageIcon();
Icon i3 = new ImageIcon();
jb1 = new JButton(i1);
jb1.setToolTipText("输入");
jb2 = new JButton(i2);
jb2.setToolTipText("查询");
jb3 = new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb = new JToolBar("系统工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("学生信息管理平台",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe, "main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jm21 || e.getSource() == jb1){
if(ip == null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe, "insert");
this.setTitle("输入学生信息");
}
else if(e.getSource() == jm22 || e.getSource() == jb2){
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe, "select");
this.setTitle("查询学生信息");
}
else if(e.getSource() == jm11 || e.getSource() == jb3){
System.exit(0);
}
}
}
第二个:
import javax.swing.JFrame;
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("学生信息管理平台");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二个:
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
static Connection getCon(){
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立数据库连接遇到异常!");
}
return con;
}
}
第四个:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl = new JLabel("请输入学号:",SwingConstants.CENTER);
jt = new JTextField();
jb = new JButton("确定");
JPanel jp1 = new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1 = new JLabel("学号:",SwingConstants.CENTER);
j2 = new JLabel("姓名:",SwingConstants.CENTER);
j3 = new JLabel("性别:",SwingConstants.CENTER);
j4 = new JLabel("年龄:",SwingConstants.CENTER);
jt1 = new JTextField(6);
jt1.setEditable(false);
jt2 = new JTextField(6);
jt2.setEditable(false);
jt3 = new JTextField(6);
jt3.setEditable(false);
jt4 = new JTextField(6);
jt4.setEditable(false);
JPanel jp2 = new JPanel(new BorderLayout());
JPanel jp3 = new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jb){
String stuNo = jt.getText().trim();
Student s = new Student();
boolean b = true;
try{
b = s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查询学生信息遇到异常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a = s.getAge();
Integer i = new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null, "无此学生!");
}
}
}
}
第五个:
import javax.swing.JFrame;
public class SelectTest {
public static void main(String [] args){
JFrame f = new JFrame("查询学生信息");
SelectPanel p = new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六个:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student {
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo = stuNo;
this.name = name;
this.gender = gender;
this.age = age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo = stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender = gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('" + stuNo + "','" + name +"','" + gender + "'," + age + ")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入数据库遇到异常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo =" + stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != null && rs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
数据库你自己弄吧,我没时间弄了!初学得多动手哦