锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 緋葷粺鐜:win2003 + j2se5.0 + tomcat5.5.7 鍓嶆彁鏄綘宸茬粡浠庣綉涓婂凡緇忎笅杞戒簡鍚勪釜鏁版嵁搴撶殑JDBC鏀寔錛?BR>鎶婇偅浜涗富瑕佺殑宸ュ叿鍖呴兘鏀懼埌Tomcat 5.5\common\lib灝辮錛?BR>鍒ㄩ櫎閭d簺鍏ラ棬鐨勪笢瑗垮惂錛岀幇鍦ㄥ紑濮嬫鍏ユ棰橈紒 1.Microsoft SQL Server 2000 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 2.MySQL 5.0 Class.forName("com.mysql.jdbc.Driver"); 3.PostgreSQL 8.0 //榪欎釜鏈嶅姟鍣ㄧ殑榛樿绔彛5432錛屽鏋滄洿鏀逛簡錛屼唬鐮佷篃闇瑕佹洿鏀?BR> Class.forName("org.postgresql.Driver"); 4.ODBC //in my opinion 浼氬啓ODBC灝卞浜嗭紝鐜板湪PostgreSQL銆丮YSQL閲屼篃閮芥湁ODBC鏀寔,浣嗛熷害鎱㈠晩! JSP銆佹湀鍘?/P>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.text.*" %> 8 package maze;
涓轟簡鍑忓皯綃囧箙錛屾洿涓轟簡鎶婇棶棰樿鐨勭洿瑙傦紝鎴戝凡緇忔妸寮傚父鎹曟崏浠g爜緇欏幓闄や簡錛?/P>
Connection conn= DriverManager.getConnection
("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=鏁版嵁搴撳悕瀛?,"sa","pwd");
Statement stmt=conn.createStatement();
//澧炲姞鍜屾煡璇㈣鍙?BR> stmt.executeUpdate("insert into boya values('mssql','2000')");
ResultSet rs=statement.executeQuery("select * from boya");
//鏄劇ず璁板綍
while(rs.next()){
out.print(rs.getString(1)+" "+rs.getString(2));
out.println("<br>");
}
Connection conn = DriverManager.getConnection
("jdbc:mysql://localhost/鏁版嵁搴撳悕瀛?user=root&password=pwd");
Statement stmt=conn.createStatement();
//澧炲姞鍜屾煡璇㈣鍙?BR> stmt.executeUpdate("insert into boya values('mysql','5.0')");
ResultSet rs=stmt.executeQuery("select * from boya");
//鏄劇ず璁板綍
while(rs.next()){
out.print(rs.getString(1)+" "+rs.getString(2));
out.println("<br>");
}
Connection conn=DriverManager.getConnection
("jdbc:postgresql://localhost:5432/鏁版嵁搴撳悕瀛?user=admin&&password=pwd");
Statement stmt=conn.createStatement();
//澧炲姞鍜屾煡璇㈣鍙?BR> stmt.executeUpdate("insert into boya values('mysql','5.0')");
ResultSet rs=stmt.executeQuery("select * from boya");
//鏄劇ず璁板綍
while(rs.next()){
out.print(rs.getString(1)+" "+rs.getString(2));
out.println("<br>");
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:test","","");
Statement stmt=conn.createStatement();
//澧炲姞鍜屾煡璇㈣鍙?BR> stmt.executeUpdate("insert into boya values('mysql','5.0')");
ResultSet rs=stmt.executeQuery("select * from boya");
//鏄劇ず璁板綍
while(rs.next()){
out.print(rs.getString(1)+" "+rs.getString(2));
out.println("<br>");
}
]]>
<html>
<head>
<title>鏈堝巻</title>
</head>
<body style="font-size:12px">
<%!
/*澹版槑鍙橀噺*/
String[] months = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
String[] months_cn = {"涓鏈?, "浜屾湀", "涓夋湀", "鍥涙湀", "浜旀湀", "鍏湀",
"涓冩湀", "鍏湀", "涔濇湀", "鍗佹湀", "鍗佷竴鏈?, "鍗佷簩鏈?};
public final static int dom[] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
};
%>
<%
/*澶勭悊浜嬩歡*/
boolean yyok = false;
int yy = 0, mm = 0;
String yyString = request.getParameter("year");
if (yyString != null && yyString.length() >0) {
try {
yy=Integer.parseInt(yyString);
yyok=true;
}
catch (NumberFormatException e) {
out.println("騫翠喚涓嶅彲鐢?);
}
Calendar cal = Calendar.getInstance();
if (!yyok)
yy = cal.get(Calendar.YEAR);
String mmString = request.getParameter("month");
if (mmString == null) {
mm = cal.get(Calendar.MONTH);
}
else {
for (int i = 0; i < months.length; i++)
if (months[i].equals(mmString)) {
mm = i;
break;
}
}
}
%>
<form name="cal" method=post action="cal.jsp">
璇烽夋嫨鏈堜喚:
<select name="month">
<%
/*鍒濆鍖栬〃鍗?/
for (int i = 0; i < months.length; i++) {
if (i == mm)
out.print("<option selected value=January>");
else
out.print("<option value="+months[i]+">");
out.print(months_cn[i]);
out.print("</option>");
}
%>
</select>
<br>璇瘋緭鍏ュ勾浠斤細
<input type="text" size="5" name="year" value="<%=yy%>">
<input type="submit" value="鏄劇ず">
</form>
<%
int lead = 0;
%>
<table border="0" cellpadding="1" cellspacing="1" style="font-size:12px">
<tr height="20"><td colspan="7"><font color="#3399FF"><b><%= months[mm]%> <%= yy%></b></font></td></tr>
<% GregorianCalendar calendar = new GregorianCalendar(yy, mm ,1); %>
<tr><td><font color="#FF0000">Sun</font></td><td>Mon</td><td>Tue</td><td>Wed</td>
<td>Thu</td><td>Fri</td><td><font color="#FF0000">Sat</font></td></tr>
<%
/*涓嬮潰鏄樉紺烘湀鍘嗙殑浠g爜*/
lead = calendar.get(Calendar.DAY_OF_WEEK)-1;
int dayInMonth = dom[mm];
if (calendar.isLeapYear(calendar.get(Calendar.YEAR)) && mm == 1)
++dayInMonth;
out.print("<tr>");
for(int i = 0; i < lead; i++) {
out.print("<td> </td>");
}
for(int i = 1; i <= dayInMonth; i++) {
if ((i+lead) % 7 == 0 || (i+lead) % 7 == 1)
out.print("<td align=\"center\"><font color=\"#FF0000\">"+i+"</font></td>");
else
out.print("<td align=\"center\">"+i+"</td>");
if ((lead+i) % 7 == 0) {
out.print("</tr></tr>");
}
}
out.print("</tr>");
%>
</table>
</body>
</html>
]]>
9
#########
#s0##0###
#0##00###
#0##0####
#0000####
#0##0####
#0##00e##
#0000####
import java.io.*;
import java.util.*;
public class Maze{
private char[][] maze;//榪峰鏁扮粍
private int startX,startY,endX,endY;//榪峰璧風偣錛岀粓鐐圭殑浣嶇疆
private int x,y,step=0;//榪峰闀垮鍙婃楠?BR> //渚濇嵁杈撳叆鐨勬枃浠跺悕鍒涘緩瀵硅薄
private Maze(String fileName){
try{
LinkedList aList=new LinkedList();//鐢ㄤ簬瀛樺偍鏂囦歡姣忚鐨勫唴瀹?BR> BufferedReader files=new BufferedReader(new FileReader("map\\"+fileName));
//灝嗘瘡琛岀殑鍐呭渚濇鍔犲叆鍒癓inkedList涓?BR> String temp=new String();
int i=0;
while((temp=files.readLine())!=null){
aList.add(temp);
}
files.close();
//璇誨彇騫惰緗糠瀹殑闀垮
x=Integer.parseInt((String)aList.getFirst())+2;
aList.removeFirst();
y=Integer.parseInt((String)aList.getFirst())+2;
aList.removeFirst();
//渚濇嵁闀垮瀵硅糠瀹繘琛屽垵濮嬪寲
maze=new char[x][y];
//灝嗚糠瀹殑璧嬩簣澶栧洿澧?BR> for(i=0;i<x;i++){
maze[i][0]='#';
maze[i][y-1]='#';
}
for(i=0;i<y;i++){
maze[0][i]='#';
maze[x-1][i]='#';
}
//灝哃inkedList涓唴瀹硅鍏ユ暟緇?BR> Iterator it=aList.iterator();
i=1;
char[] row;
while(it.hasNext()){
temp=((String)it.next());
row=new char[y-2];
row=temp.toCharArray();
for(int j=1;j<y-1;j++){
maze[i][j]=row[j-1];
if(maze[i][j]=='s'){
startX=i;
startY=j;
maze[i][j]='0';
}
else if(maze[i][j]=='e'){
endX=i;
endY=j;
maze[i][j]='0';
}
}
i++;
}
}
catch(FileNotFoundException e){
System.out.println("File Name Input Wrong!!!");
}
catch(IOException e){
System.out.println("Wrong Input!!!");
}
}
//閫掑綊鏂規硶瀵繪壘璺緞
private boolean findWay(int x,int y){
if(maze[endX][endY]=='i')
return true;
else
if(maze[x][y]=='0'){
maze[x][y]='i';
if(findWay(x-1,y))
return true;
else if(findWay(x+1,y))
return true;
else if(findWay(x,y+1))
return true;
else if(findWay(x,y-1))
return true;
else{
maze[x][y]='c';
return false;
}
}
else return false;
}
//鎵撳嵃榪峰璺緞
private void show(){
maze[startX][startY]='s';
maze[endX][endY]='e';
for(int i=1;i<x-1;i++){
for(int j=1;j<y-1;j++){
if(maze[i][j]=='i'){
maze[i][j]=' ';
step++;
}
else if(maze[i][j]=='c') maze[i][j]='0';
System.out.print(maze[i][j]);
}
System.out.println("");
}
System.out.println("I Have went "+step+" Steps To The End!");
}
public static void main(String arg[]){
try{
System.out.println("Boya(8*9)\n"+"Ice(10*12)\n"+"Sky(15*17)\n"+"Input the map name:");
BufferedReader is=new BufferedReader(new InputStreamReader(System.in));
for(;;){
String input=new String();
input=is.readLine().trim();
if(input.equals("q")) break;
else{
Maze boya=new Maze(input+".ice");
if(boya.findWay(boya.startX,boya.startY)){
boya.show();
}
else System.out.println("No Ways to the end!");
}
System.out.println("Input another map name or input 'q' to quit:");
}
is.close();
}
catch(IOException e){
System.out.println("Wrong Input!!!");
}
catch(NullPointerException e){
System.out.println("Wrong Input!!!");
}
}
}
]]>
public class Calculate{
public static boolean isOperator(String operator){
if(operator.equals("+")||operator.equals("-")||operator.equals("*")||operator.equals("/")||operator.equals("(")||operator.equals(")")) return true;
else return false;
}
public static int priority(String operator){
if(operator.equals("+")||operator.equals("-")||operator.equals("(")) return 1;
else if(operator.equals("*")||operator.equals("/")) return 2;
else return 0;
}
public static String twoResult(String operator,String a,String b){
try{
String op=operator;
String rs=new String();
double x=Double.parseDouble(b);
double y=Double.parseDouble(a);
double z=0;
if(op.equals("+")) z=x+y;
else if(op.equals("-")) z=x-y;
else if(op.equals("*")) z=x*y;
else if(op.equals("/")) z=x/y;
else z=0;
return rs+z;
}
catch(NumberFormatException e){
System.out.println("input has something wrong!");
return "Error";
}
}
}
package expression;
import java.util.*;
public class Stacks{
private LinkedList list=new LinkedList();
int top=-1;
public void push(Object value){
top++;
list.addFirst(value);
}
public Object pop(){
Object temp=list.getFirst();
top--;
list.removeFirst();
return temp;
}
public Object top(){
return list.getFirst();
}
}
package expression;
import java.io.*;
import java.util.*;
public class Expression{
private ArrayList expression=new ArrayList();//瀛樺偍涓簭琛ㄨ揪寮?BR> private ArrayList right=new ArrayList();//瀛樺偍鍙沖簭琛ㄨ揪寮?BR> private String result;//緇撴灉
//渚濇嵁杈撳叆淇℃伅鍒涘緩瀵硅薄錛屽皢鏁板間笌鎿嶄綔絎︽斁鍏rrayList涓?BR> private Expression(String input){
StringTokenizer st=new StringTokenizer(input,"+-*/()",true);
while(st.hasMoreElements()){
expression.add(st.nextToken());
}
}
//灝嗕腑搴忚〃杈懼紡杞崲涓哄彸搴忚〃杈懼紡
private void toRight(){
Stacks aStack=new Stacks();
String operator;
int position=0;
while(true){
if(Calculate.isOperator((String)expression.get(position))){
if(aStack.top==-1||((String)expression.get(position)).equals("(")){
aStack.push(expression.get(position));
}
else{
if(((String)expression.get(position)).equals(")")){
if(!((String)aStack.top()).equals("(")){
operator=(String)aStack.pop();
right.add(operator);
}
}
else{
if(Calculate.priority((String)expression.get(position))<=Calculate.priority((String)aStack.top())&&aStack.top!=-1){
operator=(String)aStack.pop();
if(!operator.equals("(")) right.add(operator);
}
aStack.push(expression.get(position));
}
}
}
else right.add(expression.get(position));
position++;
if(position>=expression.size()) break;
}
while(aStack.top!=-1){
operator=(String)aStack.pop();
right.add(operator);
}
}
//瀵瑰彸搴忚〃杈懼紡榪涜姹傚?BR> private void getResult(){
this.toRight();
Stacks aStack=new Stacks();
String op1,op2,is=null;
Iterator it=right.iterator();
while(it.hasNext()){
is=(String)it.next();
if(Calculate.isOperator(is)){
op1=(String)aStack.pop();
op2=(String)aStack.pop();
aStack.push(Calculate.twoResult(is,op1,op2));
}
else aStack.push(is);
}
result=(String)aStack.pop();
it=expression.iterator();
while(it.hasNext()){
System.out.print((String)it.next());
}
System.out.println("="+result);
}
public static void main(String avg[]){
try{
System.out.println("Input a expression:");
BufferedReader is=new BufferedReader(new InputStreamReader(System.in));
for(;;){
String input=new String();
input=is.readLine().trim();
if(input.equals("q")) break;
else{
Expression boya=new Expression(input);
boya.getResult();
}
System.out.println("Input another expression or input 'q' to quit:");
}
is.close();
}
catch(IOException e){
System.out.println("Wrong input!!!");
}
}
}