<%@ page contentType="text/html;charset=gb2312"%>
<%@page import ="java.sql.*"%>
<%--
使用JDBC连接Oracle数据库
使用MLDN数据库
用户名:scott
密码:tiger
--%>
<%!
String DBDRIVER="oracle.jdbc.driver.OracleDriver";
String DBURL="jadb:oracle:thin:@localhost:1521:mldn";
String DBUSER="scott";
String DBPASSWORD="tiger";
Connection conn=null;
statement stmt=null;
%>
<%try{Class.forname(DBDRIVER);
conn=DriverManger.getConnection(DBURL,DBUSER,DBPASSWORD);
//create table
String sql="CREATE TABLE mldnab(name vachar(20))";
stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}catch(Exception e){
out.println(e);
}
/**
*测试类构造器的调用顺序
*/
public class ConstructorTest{
public static void main(String[] args){
C c=new C("hello");
}
}
class A{
public A(){
System.out.println("this is A");
}
}
class C extends B{
public C(String str){
super(str);
System.out.println("this is C");
}
}
public class ToStringTest{
public static void main(String[] args){
System.out.println(new Student("youName","20031001"));
}
}
/**
*通过这个程序,展示字符串求取子串的方法
*/
public class SubStringTest{
public static void main(String[] args){
String str="I am a Programmer";//定义字符串
for(int i=0;i<str.length();i++){
System.out.println("这是第"+i+"个子串:"+str.subString(i));
}}}
/**
*读取键盘输入
*/
import javax.swing.JOptionPane;
public class InputTest{
public static void main(String[] args){
String strName=JOptionPane.showInputDialog("Input your name:");
String strAge=JOptionPane.showInputDialog("Input your age:");
int age=Integer.parseInt(strAge);
System.out.println("Welcome you :"+strName);
System.out.println("你还有"+(60-age)+"年可以退休了!!");
System.exit(0);
}
}
/**
*通过这个程序,测试格式器的使用方法
*/
import java.text.NumberFormat;
import java.util.locale;
public class FormateValue{
public static void main(String[] args){
double x=100000.0/3;
System.out.println("the value is :"+x);
//首先以默认地区的格式器来输出
System.out.println("接下来输出的是美国地区的格式器的结果:");
NumberFormat number=NumberFormat.getNumberInstance(Locale.US);
NumberFormat number=NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat percent=NumberFormat.getPercentInstance(Locale.US);
FormatValue fm=new FormatValue();
fm.print(number,x);
fm.print(currency.x);
fm.print(percent,x);
System.out.println("接下来输出的是默认地区的格式器的结果:");
NubmerFormat nu=NumberFormat.getNumberInstance();
NubmerFormat cu=NumberFormat.getCurrencyInstance();
NubmerFormat be=NumberFormat.getPercentIntstance();
fm.print(nu,x);
fm.print(cu,x);
fm.print(pe,x);
}
public void print(NubmerFormat nu,double x){
System.out.println(nu.format(x));
}
}
/**
*查找特定的子串
*/
public class FindSubstring{
public static void main(String[] args){
String str="Welcome the body.";
System.out.println("Find the substring boy occurrence:"+str.indexOf("boy"));//查找子串
System.out.println("Find the substring by occurrence: "+str.indexOf("by"));//查找子串
System.out.println("Find the char t occurrence: "+str.indexOf('t'));//查找特定的字符
System.out.println("Test the string begin with wel.:"+str.startsWith("wel"));//是否以"wel"开始
System.out.pritnln("Test the string end with body.:"+str.endWith("boy"));//是否以"boy"结束
}
}