⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cao.java

📁 这个是我们做土地局的一个项目。感觉不错。欢迎下载
💻 JAVA
字号:
package huayi.gg.cao;

import java.sql.*;
import java.io.*;
import java.util.*;

public class cao{
String mydbdriver="sun.jdbc.odbc.JdbcOdbcDriver"; 
String url="jdbc:odbc:cao"; 
Connection conn = null; 
ResultSet rs = null;
Statement stmt = null;
PreparedStatement pre;
Calendar calendar=Calendar.getInstance();
String houzhui=null;
File f1;
RandomAccessFile random;
FileOutputStream o;
String secondLine;
int second=1;
int position;
String fileName;
byte b[]=new byte[10000];
int n;
public void dbconn(){
try {
     Class.forName(mydbdriver);  
     //取得连接的url名,注意Jspodbc是dsn名 
     }
catch(java.lang.ClassNotFoundException e) { 
      System.err.print("ClassNotFoundException: "); 
      //加载jdbc-odbc桥错误 
      System.err.println(e.getMessage()); 
      //其他错误 	
	}
try {   
     conn=DriverManager.getConnection(url,"cao","home");    
     } catch(SQLException e) { 
      System.err.println("SQLException: " + e.getMessage()); 
      //显示数据库连接错误或者查询错误 
                             }    
}
//数据查询
public ResultSet executeQuerya(String sql){

rs = null;
try {   
     stmt=conn.createStatement();                                                               
     rs=stmt.executeQuery(sql);
     } catch(SQLException ex){
       System.err.println("sql_data.executeUpdate:"+ex.getMessage());
     //显示数据库连接错误或者查询错误 
                             }   
     return rs;                          
    }

public ResultSet executeQueryb(String sql){

rs = null;
try {   
     stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);                                                               
     rs=stmt.executeQuery(sql);
     } catch(SQLException ex){
       System.err.println("sql_data.executeUpdate:"+ex.getMessage());
     //显示数据库连接错误或者查询错误 
                             }   
     return rs;                          
    }
//数据更新
public int executeUpdate(String sql){
Statement stmt = null;
int number = 0;
try {
       if (conn==null) { return -1; }
       stmt = conn.createStatement();
       if (stmt == null) { return -1; }
       stmt.executeUpdate(sql);
        } catch(SQLException ex){
       System.err.println("sql_data.executeUpdate:"+ex.getMessage());
       return -1;
        }
       return number;
    }
	
public String getName(InputStream in,String tempFileName)
{

try
{
  f1=new File("e:/picture",tempFileName);
  o=new FileOutputStream(f1);
  while((n=in.read(b))!=-1){o.write(b,0,n);}
  o.close();
  in.close();
  random=new RandomAccessFile(f1,"r");
  secondLine=null;
  while(second<=2)
  {secondLine=random.readLine();second++;}
  position=secondLine.lastIndexOf('\\');
  fileName=secondLine.substring(position+1,secondLine.length()-1);
  int position0=fileName.lastIndexOf('.');
  houzhui=fileName.substring(position0+1,fileName.length());  
}
catch(IOException e){}
  return houzhui;
}
//文件上传
public void transfer(String sql)
{
try
{
  random.seek(0);
  long forthEndPosition=0;
  int forth=1;
  while((n=random.readByte())!=-1&&(forth<=4))
   {
    if(n=='\n')
    {
	    forthEndPosition=random.getFilePointer();
        forth++;
	}
   }
  File f2=new File("e:/picture",fileName);
  RandomAccessFile random2=new RandomAccessFile(f2,"rw");
  random.seek(random.length());
  long endPosition=random.getFilePointer();
  long mark=endPosition;
  int j=1;
  while((mark>=0)&&(j<=6))
 {
   mark--;
   random.seek(mark);
   n=random.readByte();
   if(n=='\n')
   {endPosition=random.getFilePointer();j++;}
 }
  random.seek(forthEndPosition);
  long startPoint=random.getFilePointer();
  while(startPoint<endPosition-1)
 {
   n=random.readByte();
   random2.write(n);
   startPoint=random.getFilePointer();
 }
 FileInputStream inn=new FileInputStream(f2);
 try
{
 pre=conn.prepareStatement(sql);
 pre.setBinaryStream(1,inn,inn.available());
 int number=pre.executeUpdate();
}
catch(SQLException ex)
{
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
 random2.close();
 random.close();
 //f1.delete();
 //f2.delete();
   
}
catch(IOException e){}
}
//获取日期
public void calendar()
{
	calendar.setTime(new java.util.Date());
}
public int getYear()
{
	int year=calendar.get(Calendar.YEAR);
	return year;
}
public int getMonth()
{
	int month=calendar.get(Calendar.MONTH)+1;
	return month;
}
public int getDate()
{
	int date=calendar.get(Calendar.DAY_OF_MONTH);
	return date;
}
//close
public int close()
{  
 int number = 0;
   try
	{
	stmt.close();
	conn.close();
	}
	catch(SQLException ex)
	{
    System.err.println("sql_data.executeUpdate:"+ex.getMessage());
    return -1;
	}
	return number;
}
   
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -