當前位置:首頁 » 操作系統 » java版系統源碼

java版系統源碼

發布時間: 2025-01-25 05:34:22

『壹』 求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;
}
}
資料庫你自己弄吧,我沒時間弄了!初學得多動手哦

熱點內容
領航s1配置怎麼樣 發布:2025-01-26 09:58:10 瀏覽:763
公司區域網搭建伺服器搭建 發布:2025-01-26 09:16:56 瀏覽:433
android裁剪圓形圖片 發布:2025-01-26 09:05:56 瀏覽:411
小貸源碼 發布:2025-01-26 08:20:58 瀏覽:536
更換電腦名登錄伺服器 發布:2025-01-26 07:56:52 瀏覽:240
後台phpjava 發布:2025-01-26 07:12:34 瀏覽:657
微信解綁密碼是什麼 發布:2025-01-26 06:50:07 瀏覽:734
app如何訪問伺服器 發布:2025-01-26 06:36:56 瀏覽:741
拳皇安卓單機哪裡下載 發布:2025-01-26 06:30:46 瀏覽:539
注冊會員時積分消費密碼是什麼 發布:2025-01-26 06:30:45 瀏覽:247