资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java简易系统源代码,java管理系统源代码

java点名系统源代码

import java.awt.GridLayout;

为衡阳县等地区用户提供了全套网页设计制作服务,及衡阳县网站建设行业解决方案。主营业务为成都做网站、成都网站设计、衡阳县网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Scanner;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextField;

public class test {

static String[] arr;

static boolean flag=true;

static ListString a;

static JTextField jtf;

public static void main(String[] args) {

// TODO Auto-generated method stub

JFrame frame=new JFrame();

frame.setLayout(new GridLayout(1,2));

JButton button = new JButton("抽奖");

jtf = new JTextField();

frame.add(jtf);

frame.add(button);

a = new ArrayListString();

arr = new String[]{"张三","李四","王五"};

button.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

int i=0;

fond:

while(true){

String str = arr[(int)(Math.random()*arr.length)];

for(String b:a){

if(b.equals(str)){

if(i=arr.length){

jtf.setText("没有人了");

break fond;

}

continue fond;

}

i++;

}

a.add(str);

jtf.setText(str);

break;

}

}

});

frame.setSize(500, 500);

frame.setLocation(500, 500);

frame.setVisible(true);

}

}

谁有Java实现的学生信息管理系统源码

可以试试看啊

以下方法实现了用户界面登陆

import java.awt.*;

import java.awt.event.*;

public class DengLuJieMian extends Frame implements ActionListener

{

Label username=new Label("用户名:");//使用文本创建一个用户名标签

TextField t1=new TextField();//创建一个文本框对象

Label password=new Label("密码:");//创建一个密码标签

TextField t2=new TextField();

Button b1=new Button("登陆");//创建登陆按钮

Button b2=new Button("取消");//创建取消按钮

public DengLuJieMian()

{

this.setTitle("学生信息管理系统");//设置窗口标题

this.setLayout(null);//设置窗口布局管理器

username.setBounds(50,40,60,20);//设置姓名标签的初始位置

this.add(username);// 将姓名标签组件添加到容器

t1.setBounds(120,40,80,20);// 设置文本框的初始位置

this.add(t1);// 将文本框组件添加到容器

password.setBounds(50,100,60,20);//密码标签的初始位置

this.add(password);//将密码标签组件添加到容器

t2.setBounds(120,100,80,20);//设置密码标签的初始位置

this.add(t2);//将密码标签组件添加到容器

b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置

this.add(b1);//将登陆按钮组件添加到容器

b2.setBounds(120,150,60,20);//设置取消按钮的初始位置

this.add(b2);// 将取消按钮组件添加到容器

b1.addActionListener(this);//给登陆按钮添加监听器

b2.addActionListener(this);// 给取消按钮添加监听器

this.setVisible(true);//设置窗口的可见性

this.setSize(300,200);//设置窗口的大小

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

});//通过内部类重写关闭窗体的方法

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==b1)//处理登陆事件

{

String name=t1.getText();

String pass=t2.getText();

if(name!=nullpass.equals("000123"))//判断语句

{

new StudentJieMian();

}

}

}

public static void main(String args[])//主函数

{

new DengLuJieMian();

}

}

以下方法实现了学生界面设计

import java.awt.*;

import java.awt.event.*;

class StudentJieMian extends Frame implements ActionListener

{

MenuBar m=new MenuBar();//创建菜单栏

Menu m1=new Menu("信息");//创建菜单“信息”

MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项

MenuItem m12=new MenuItem("查询");

Menu m2=new Menu("成绩");//创建菜单“成绩”

MenuItem m21=new MenuItem("查询");

public StudentJieMian()

{

this.setTitle("学生界面");//设置窗口标题

this.setLayout(new CardLayout());//设置窗口布局管理器

this.setMenuBar(m);//将菜单栏组件添加到容器

m.add(m1);//将信息菜单放入菜单栏

m.add(m2);

m1.add(m11);//将“插入”菜单项添加到“信息”菜单

m1.add(m12); //将“查询”菜单项添加到“信息”菜单

m2.add(m21); //将“查询”菜单项添加到“成绩”菜单

m11.addActionListener(this); //给“插入”菜单项添加监听器

m12.addActionListener(this); //给“查询”菜单项添加监听器

m21.addActionListener(this); //给“查询”菜单项添加监听器

this.setVisible(true); //设置窗口的可见性

this.setSize(300,200); //设置窗口的大小

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);//关闭窗口

}

});

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==m11) //处理“添加信息”事件

{

new AddStudent();

}

if(e.getSource()==m12) //处理“查询信息”事件

{

new SelectStudent();

}

if(e.getSource()==m21) //处理“查询成绩”事件

{

new ChengJiStudent();

}

}

public static void main(String args[])

(高分)急求连接数据库的JAVA学生信息管理系统源代码

数据库连接(Connection)

数据库连接

获取数据库连接有两种方法,一种是通过驱动程序管理器DriverManager类,另一种则是使用DataSource接口。这两种方法都提供了了一个getConnection方法,用户可以在程序中对它们进行相应处理后调用这个方法来返回数据库连接。

• DriverManager类

• DataSource接口

• Connection接口

• JDBC URL

jdbc:subprotocol:subname

• 驱动程序注册方法

(1)调用Class.forName方法

(2)设置jdbc.drivers系统属性

• DriverManager方法

DriverManager类中的所有方法都是静态方法,所以使用DriverManager类的方法时,不必生成实例。

DriverManager

• getConnection方法

作用是用于获取数据库连接,原型如下:

public static Connection getConnection(String url)

throws SQLException;

public static Connection getConnection(String url, String user, String password)

throws SQLException;

public static Connection getConnection(String url, Properties info)

throws SQLException;

• 使用DriverManager的getConnetion方法

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn = DriverManager.getConnection

("jdbc:odbc:sqlserver", "sa", "sa");

• 使用设置jdbc.drivers系统属性的方法

java -Djdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver test.java

DataSource 接口

……

//从上下文中查找数据源,并获取数据库连接

Context ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("sqlserver");

Connection conn = ds.getConnection();

//查询数据库中所有记录

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM student");

……

Connection 接口

Connection接口代表了已经建立的数据库连接,它是整个JDBC的核心内容。Connnection接口中的方法按照它们所实现的功能,可以分为三类:

• 生成数据库语句

• 管理数据库事务

• 获取数据库信息

生成数据库语句

JDBC将数据库语句分成三种类型 :

• 生成Statement 语句 :

Connection.createStatement()

• 生成PreparedStatement 语句 :

Connection. prepareStatement()

• 生成CallableStatement 语句 :

Connection. prepareCall ()

管理数据库事务

• 默认情况下,JDBC将一条数据库语句视为一个完整的事务。可以关掉默认事务管理:

public void setAutoCommit(Boolean autoCommit) throws SQLException;

将autoCommit的值设置为false,就关掉了自动事务管理模式

• 在执行完事务后,应提交事务:

public void commit() throws SQLException;

• 可以取消事务:

public void rollback() throws SQLException;

第二讲 第四部分

数据库语句

数据库语句

JDBC数据库语句共有三种类型:

• Statement:

Statement语句主要用于嵌入一般的SQL语句,包括查询、更新、插入和删除等等。

• PreparedStatement:

PreparedStatement语句称为准备语句,它是将SQL语句中的某些参数暂不指定,而等到执行时在统一指定。

• CallableStatement:

CallableStatement用于执行数据库的存储过程。

Statement 语句

• executeQuery方法

• executeUpdate方法

• execute方法

• close方法

executeQuery方法

• executeQuery方法主要用于执行产生单个结果集的SQL查询语句(QL),即SELECT语句。executeQuery方法的原型如下所示:

• public ResultSet executeQuery(String sql) throws SQLException;

executeUpdate方法

• executeUpdate方法主要用于执行 INSERT、UPDATE、DELETE语句,即SQL的数据操作语句(DML)

• executeUpdate方法也可以执行类似于CREATE TABLE和DROP TABLE语句的SQL数据定义语言(DDL)语句

• executeUpdate方法的返回值是一个整数,指示受影响的行数(即更新计数)。而对于CREATE TABLE 或 DROP TABLE等并不操作特定行的语句,executeUpdate的返回值总为零。

execute方法

execute方法用于执行:

• 返回多个结果集

• 多个更新计数

• 或二者组合的语句

execute方法

• 返回多个结果集:首先要调用getResultSet方法获得第一个结果集,然后调用适当的getter方法获取其中的值。要获得第二个结果集,需要先调用getMoreResults方法,然后再调用getResultSet方法。

• 返回多个更新计数:首先要调用getUpdateCount方法获得第一更新计数。然后调用getMoreResults,并再次调用getUpdateCount获得后面的更新计数。

• 不知道返回内容:如果结果是ResultSet对象,则execute方法返回true;如果结果是int类型,则意味着结果是更新计数或执行的语句是DDL命令。

execute方法

为了说明如果处理execute方法返回的结果,下面举一个代码例子:

stmt.execute(query);

while (true) {

int row = stmt.getUpdateCount();

//如果是更新计数

if (row 0) {

System.out.println("更新的行数是:" + row);

stmt.getMoreResults();

continue;

}

execute方法

//如果是DDL命令或0个更新

if (row == 0) {

System.out.println("没有更新,或SQL语句是一条DDL语句!");

stmt.getMoreResults();

continue;

}

//如果是一个结果集

ResultSet rs = stmt.getResultSet;

if (rs != null) {

while (rs.next()) {

// 处理结果集

. . .

}

stmt.getMoreResults();

continue;

}

break;

}

PreparedStatement 语句

登录一个网站或BBS时 :

• 使用Statement语句

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery

(“SELECT password FROM userinfo

WHERE id=userId");

• 使用PreparedStatement语句

PreparedStatement pstmt=conn.prepareStatement

(“SELECT password FROM userinfo

WHERE id=?");

pstmt.setString(1, userId);

PreparedStatement语句

• 常用的setter方法

public void setBoolean(int parameterIndex, boolean x) throws SQLException;

public void setByte(int parameterIndex, byte x) throws SQLException;

public void setShort(int parameterIndex, short x) throws SQLException;

public void setInt(int parameterIndex,int x) throws SQLException;

public void setLong(int parameterIndex, long x) throws SQLException;

public void setFloat(int parameterIndex, float x) throws SQLException;

public void setDouble(int parameterIndex, double x) throws SQLException;

public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException;

public void setString(int parameterIndex, String x) throws SQLException;

public void setBytes(int parameterIndex, byte[] x) throws SQLException;

public void setDate(int parameterIndex, Date x) throws SQLException;

public void setTime(int parameterIndex, Time x) hrows SQLException;

public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException;

PreparedStatement语句

• PreparedStatement接口是由Statement接口扩展而来的,重写了executeQuery方法、executeUpdate方法和execute 方法

• public ResultSet executeQuery() throws SQLException

• public int executeUpdate() throws SQLException

• public boolean execute() throws SQLException

CallableStatement语句

• CallableStatement语句是由Connection接口的prepareCall方法创建的,创建时需要传入字符串参数,参数的形式为:

• {call procedure_name[(?, ?, ...)]}

• {? = call procedure_name[(?, ?, ...)]}

• {call procedure_name}

CallableStatement语句

• 其中的问号是参数占位符,参数共有两种:

• IN参数

• OUT参数

• IN参数使用setter方法来设置

• OUT参数则使用registerOutParameter方法来设置

CallableStatement 语句

CallableStatement cstmt = con.prepareCall

("{call getTestData(?, ?)}");

cstmt.registerOutParameter

(1, java.sql.Types.TINYINT);

cstmt.registerOutParameter

(2, java.sql.Types.DECIMAL, 3);

cstmt.executeQuery();

byte x = cstmt.getByte(1);

java.math.BigDecimal n =

cstmt.getBigDecimal(2, 3);

第二讲 第五部分

结 果 集

结果集

• JDBC为了方便处理查询结果,又专门定义了一个接口,这个接口就是ResultSet接口。ResultSet接口提供了可以访问数据库查询结果的方法,通常称这个接口所指向的对象为结果集。

• 有两种方法得到结果集,一种是直接执行查询语句,将结果存储在结果集对象上;另一种是不存储返回结果,而在需要时调用数据库语句的getResultSet方法来返回结果集

结果集

• 结果集指针

由于返回的结果集可能包含多条数据记录,因此ResultSet 接口提供了对结果集的所有数据记录轮询的方法。结果集自动维护了一个指向当前数据记录的指针,初始时这个指针是指向第一行的前一个位置。 next 方法就是用于向前移动指针的

结果集

• 结果集属性

默认情况下,结果集是一个不可更新集,并且结果集的指针也只能向前移动。也就是说,在得到了一个结果集之后,用户只能按照从第一条记录到最后一条记录的顺序依次向后读取,而不能跳到任意条记录上,也不能返回到前面的记录。不仅如此,结果集的这种轮询只能进行一次,而不能再将指针重置到初始位置进行多次轮询

结果集

• 结果集属性

类型

并发性

有效性

• 属性的设置是在生成数据库语句时通过向生成方法传入相应的参数设定的,而当结果集已经返回时就不能够再改变它的属性了。

结果集生成Statement语句共有三种方法

public Statement createStatement() throws SQLException;

public Statement createStatement

(int resultSetType, int resultSetConcurrency)

throws SQLException;

public Statement createStatement

(int resultSetType, int resultSetConcurrency,

int resultSetHoldability)

throws SQLException;

结果集

• 生成PreparedStatement语句共有六种方法

public PreparedStatement prepareStatement(String sql) throws SQLException;

public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)

throws SQLException;

public PreparedStatement prepareStatement(String sql, int[] columnIndexes)

throws SQLException;

public PreparedStatement prepareStatement(String sql, int resultSetType,

int resultSetConcurrency)

throws SQLException;

public PreparedStatement prepareStatement(String sql, int resultSetType,

int resultSetConcurrency,

int resultSetHoldability)

throws SQLException;

public PreparedStatement prepareStatement(String sql. String[] columnNames)

throws SQLException;

结果集

• 生成CallableStatement语句共有三种方法

public CallableStatement prepareCall(String sql)

throws SQLException;

public CallableStatement prepareCall

(String sql, int resultSetType,

int resultSetConcurrency)

throws SQLException;

public CallableStatement prepareCall

(String sql, int resultSetType,

int resultSetConcurrency,

int resultSetHoldability)

throws SQLException;

结果集

结果集类型

• 结果集的类型共有三种,TYPE_FORWARD_ONLY类型的结果集只能向前移动指针,而TYPE_SCROLL_INSENSITIVE类型和TYPE_SCROLL_SENSITIVE类型的结果集则可以任意移动指针。后两种类型的区别在于,前者对来自其它处的修改不敏感(静态),而后者则对于别人的修改敏感(动态视图)。

结果集

结果集类型

• 对于可以任意移动指针的结果集,可以用来移动指针的方法包括:

• next 和previous :

• absolute 和relative :参数可正可负

• afterLast 、beforeFirst 、last 和first :

结果集

结果集并发性

• 结果集的并发性共有两种,CONCUR_READ_ONLY的结果集是只读而不可更新的;而CONCUR_UPDATABLE的结果集则是可以通过update方法进行更新的。

• ResultSet接口提供了一组update方法,用于更新结果集中的数据。这些方法与PreparedStatement接口中定义的setter方法一样,也是与类型相对应的。所有的update方法都以update开头 。

• 所有的update方法都有两个参数,第一个参数用于指定更新的列,它可以是列名称也可以是列的序号;第二个参数则表示将要更新列的值。

结果集

结果集并发性

• Statement stmt = conn.createStatement

• (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

• ResultSet rs = stmt.executeQuery("SELECT * FROM student " +

• "WHERE grade=2 AND math60 AND physics60 AND " +

• "chemistry60 AND english60 AND chinese60");

• while(rs.next()){

• rs.updateString("grade", "3");

• rs.updateRow();

• }

结果集

结果集有效性

• 结果集的有效性是指在调用了Connection 接口的commit 方法后,结果集是否自动关闭。所以它只有两个可选值,即HOLD_CURSORS_OVER_COMMIT 和CLOSE_CURSORS_AT_COMMIT 。前者表示调用commit 方法之后,结果集不关闭;而后者则表示关闭结果集。

结果结果集

• 结果集的getter方法

ResultSet接口还提供了一组getter方法,用于返回当前记录的属性值。它们都是以get开头的,后接数据类型。比如,如果要返回一个float类型的列值,则应调用getFloat方法。每一种类型的getter方法都有两种形式,它们的名称相同而参数不同。这两种形式的getter方法都只有一个参数,第一种形式的getter方法参数是String类型的,用于指定列的名称;另外一种形式的getter方法参数则是int类型的,用于指定列的序号。

求JAVA简易计算机源代码

试试这个

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.applet.*;

public class SZJSQ extends JApplet implements ActionListener

{

boolean i=true;

private JButton num0=new JButton("0");

private JButton num1=new JButton("1");

private JButton num2=new JButton("2");

private JButton num3=new JButton("3");

private JButton num4=new JButton("4");

private JButton num5=new JButton("5");

private JButton num6=new JButton("6");

private JButton num7=new JButton("7");

private JButton num8=new JButton("8");

private JButton num9=new JButton("9");

private JButton zuok=new JButton("(");

private JButton youk=new JButton(")");

private JButton dian=new JButton(".");

private JButton NULL=new JButton("N");

private JButton plu=new JButton("+");

private JButton min=new JButton("-");

private JButton mul=new JButton("x");

private JButton div=new JButton("/");

private JButton equ=new JButton("=");

private JButton cle=new JButton("C");//清除

private JTextField space=new JTextField(30);

public void init()

{

JPanel text=new JPanel();

text.setLayout(new FlowLayout());

text.add(space);

JPanel buttons=new JPanel();

buttons.setLayout(new GridLayout(5,4));

buttons.add(num9);

buttons.add(num8);

buttons.add(num7);

buttons.add(plu);

buttons.add(num6);

buttons.add(num5);

buttons.add(num4);

buttons.add(min);

buttons.add(num3);

buttons.add(num2);

buttons.add(num1);

buttons.add(mul);

buttons.add(num0);

buttons.add(cle);

buttons.add(equ);

buttons.add(div);

buttons.add(zuok);

buttons.add(youk);

buttons.add(dian);

buttons.add(NULL);

(num9).addActionListener(this);

(num8).addActionListener(this);

(num7).addActionListener(this);

(num6).addActionListener(this);

(num5).addActionListener(this);

(num4).addActionListener(this);

(num3).addActionListener(this);

(num2).addActionListener(this);

(num1).addActionListener(this);

(num0).addActionListener(this);

(plu).addActionListener(this);

(min).addActionListener(this);

(mul).addActionListener(this);

(div).addActionListener(this);

(equ).addActionListener(this);

(cle).addActionListener(this);

(zuok).addActionListener(this);

(youk).addActionListener(this);

(dian).addActionListener(this);

setLayout(new BorderLayout());

add("North",text);

add("South",buttons);

space.setText("0");

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==num9)

{

if(i==true)

{

space.setText("9");

i=false;

}

else space.setText(space.getText()+'9');

}

if(e.getSource()==num8)

{

if(i==true)

{

space.setText("8");

i=false;

}

else space.setText(space.getText()+'8');

}

if(e.getSource()==num7)

{

if(i==true)

{

space.setText("7");

i=false;

}

else space.setText(space.getText()+'7');

}

if(e.getSource()==num6)

{

if(i==true)

{

space.setText("6");

i=false;

}

else space.setText(space.getText()+'6');

}

if(e.getSource()==num5)

{

if(i==true)

{

space.setText("5");

i=false;

}

else space.setText(space.getText()+'5');

}

if(e.getSource()==num4)

{

if(i==true)

{

space.setText("4");

i=false;

}

else space.setText(space.getText()+'4');

}

if(e.getSource()==num3)

{

if(i==true)

{

space.setText("3");

i=false;

}

else space.setText(space.getText()+'3');

}

if(e.getSource()==num2)

{

if(i==true)

{

space.setText("2");

i=false;

}

else space.setText(space.getText()+'2');

}

if(e.getSource()==num1)

{

if(i==true)

{

space.setText("1");

i=false;

}

else space.setText(space.getText()+'1');

}

if(e.getSource()==num0)

{

if(i==true)

{

space.setText("0");

i=false;

}

else space.setText(space.getText()+'0');

}

if(e.getSource()==zuok)

{

if(i==true)

{

space.setText("(");

i=false;

}

else space.setText(space.getText()+'(');

} if(e.getSource()==youk)

{

if(i==false)

space.setText(space.getText()+')');

}

if(e.getSource()==dian)

{

if(i==false)

space.setText(space.getText()+'.');

}

if(e.getSource()==plu)

{

space.setText(space.getText()+'+');

i=false;

}

if(e.getSource()==min)

{

space.setText(space.getText()+'-');

i=false;

}

if(e.getSource()==mul)

{

space.setText(space.getText()+'*');

i=false;

}

if(e.getSource()==div)

{

space.setText(space.getText()+'/');

i=false;

}

if(e.getSource()==equ)

{

space.setText(String.valueOf(Calculator(space.getText())));

i=true;

}

if(e.getSource()==cle)

{

space.setText("0");

i=true;

}

}

public double Calculator(String f)//科学计算

{

int i=0,j=0,k;

char c;

StringBuffer s=new StringBuffer();

s.append(f);

s.append('=');

String formula=s.toString();

char[] anArray;

anArray=new char[50];

StackCharacter mystack=new StackCharacter();

while(formula.charAt(i)!='=')

{

c=formula.charAt(i);

switch(c)

{

case '(': mystack.push(new Character(c));

i++;

break;

case ')':

while(mystack.peek().charValue()!='(')

{

anArray[j++]=mystack.pop().charValue();

}

mystack.pop();

i++;

break;

case '+':

case '-':

while(!mystack.empty()mystack.peek().charValue()!='(')

{

anArray[j++]=mystack.pop().charValue();

}

mystack.push(new Character(c));

i++;

break;

case '*':

case '/':

while(!mystack.empty()(mystack.peek().charValue()=='*'||mystack.peek().charValue()=='/'))

{

anArray[j++]=mystack.pop().charValue();

}

mystack.push(new Character(c));

i++;

break;

case' ': i++;

break;

default: while((c='0'c='9')||c=='.')

{

anArray[j++]=c;

i++;

c=formula.charAt(i);

}

anArray[j++]='#';

break;

}

}

while(!(mystack.empty()))

anArray[j++]=mystack.pop().charValue();

i=0;

int count;

double a,b,d;

StackDouble mystack1 =new StackDouble();

while(ij)

{

c=anArray[i];

switch(c)

{

case '+':

a=mystack1.pop().doubleValue();

b=mystack1.pop().doubleValue();

d=b+a;

mystack1.push(new Double(d));

i++;

break;

case '-':

a=mystack1.pop().doubleValue();

b=mystack1.pop().doubleValue();

d=b-a;

mystack1.push(new Double(d));

i++;

break;

case '*':

a=mystack1.pop().doubleValue();

b=mystack1.pop().doubleValue();

d=b*a;

mystack1.push(new Double(d));

i++;

break;

case '/':

a=mystack1.pop().doubleValue();

b=mystack1.pop().doubleValue();

if(a!=0)

{

d=b/a;

mystack1.push(new Double(d));

i++;

}

else

{

System.out.println("Error!");

}

break;

default:

d=0;count=0;

while((c='0'c='9'))

{

d=10*d+c-'0';

i++;

c=anArray[i];

}

if(c=='.')

{

i++;

c=anArray[i];

while((c='0'c='9'))

{

count++;

d=d+(c-'0')/Math.pow(10,count);

i++;

c=anArray[i];

}

}

if(c=='#')

mystack1.push(new Double(d));

i++;

break;

}

}

return(mystack1.peek().doubleValue());

}

}

用JAVA编程的通过SQL连接数据库的商品库存管理系统的源代码

package com.company.dao;

import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class BaseDao {

// 数据库驱动

String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

//url

String url = "jdbc:sqlserver://数据库ip:端口号;databaseName=数据库名;";

//用户名

String uname = "数据库用户名";

//密码

String pwd = "数据库密码";

/**

* 获得连接对象

* @return

*/

protected Connection getCon(){

//返回的连接

Connection con = null;

try {

//载入驱动

Class.forName(driver);

//得到连接

con = DriverManager.getConnection(url, uname, pwd);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

}

return con;

}

/**

* 关闭数据库

* @param con

* @param stmt

* @param rs

*/

protected void closeDB(Connection con, Statement stmt, ResultSet rs){

if(rs != null){

try {

//关闭结果集

rs.close();

rs = null;

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if(stmt != null){

try {

//关闭语句对象

stmt.close();

stmt = null;

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if(con != null){

try {

//关闭连接对象

con.close();

con = null;

} catch (SQLException e) {

e.printStackTrace();

}

}

}

protected void closeDB(Connection con, PreparedStatement pstmt, ResultSet rs){

if(rs != null){

//关闭结果集

try {

rs.close();

rs = null;

} catch (SQLException e) {

e.printStackTrace();

}

}

if(pstmt != null){

try {

pstmt.close();

pstmt = null;

} catch (SQLException e) {

e.printStackTrace();

}

}

if(con != null){

try {

con.close();

con = null;

} catch (SQLException e) {

e.printStackTrace();

}

}

}

这个是我写的一个基本的连接sql2005数据库的代码,.! 不知道你能不能用,! 你看一下吧, 连接的时候需要sqljdbc.jar数据库驱动,!


新闻标题:java简易系统源代码,java管理系统源代码
本文地址:http://cdkjz.cn/article/hecesi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220