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

📄 funcoper.java

📁 本程序是微型的管理系统
💻 JAVA
字号:
import java.util.*;
import java.sql.*;
import java.io.*;
 class FieldInfo
     {
		public String strFieldName;   
		String strFieldType;     
     }
 class TableInfo
	{
		String strTableName;	 
		Vector vecFields = new Vector();
		String strInfomation;		 
	}

public class funcOper         
	{
		TableInfo  tInfo = new TableInfo();
		Vector v = new Vector();
		void setTableName(String strTableName) 
		{       
			
			tInfo.strTableName= strTableName;
                        
                 }
                

		void setFieldName(String strFieldsName) 
		{	
			
			StringTokenizer st = new StringTokenizer(strFieldsName,",");
			
		        while(st.hasMoreTokens())
			{
			 FieldInfo ff = new FieldInfo();
                         ff.strFieldName = st.nextToken();
			 tInfo.vecFields.add(ff);
			}
			FieldInfo ss = new FieldInfo();
			for(int i =0;i<6;i++)
                        { 
			  ss = (FieldInfo)tInfo.vecFields.elementAt(i);
			  String s = ss.strFieldName;
                         System.out.println(s);	}

		} 

		void setFieldType(String strFieldsType)  
		{       
            		StringTokenizer st = new StringTokenizer(strFieldsType,",");			
		        int i =0;
			while(st.hasMoreTokens())
			{
			 FieldInfo ff = new FieldInfo();
                         ff.strFieldType= st.nextToken();
			 tInfo.vecFields.add(ff);
			}
			FieldInfo ss = new FieldInfo();
                        for(i =0;i<6;i++)
                        { 
			  ss = (FieldInfo)tInfo.vecFields.elementAt(i);
			  String s = ss.strFieldType;
                         System.out.println(s);	}
		}
		
		void setInfomation(String strInfomation)  
		{      
            		StringTokenizer st = new StringTokenizer(strInfomation," ");
			String s;
		        while(st.hasMoreTokens())
			{
			  v.add(st.nextToken());
			}
		}

		String getCreateTableSQL()
		{	
			
			
			String strSQL = "create table ";
			strSQL += tInfo.strTableName;
			strSQL += "(";
			int i=0;
			FieldInfo fInfo = new FieldInfo(); 
			for(i=0; i<tInfo.vecFields.size()-1; i++)
			{	
				
				fInfo = (FieldInfo)tInfo.vecFields.elementAt(i);
				strSQL += fInfo.strFieldName;
				strSQL += " ";
				strSQL += fInfo.strFieldType;
				strSQL += ",";
			}
			fInfo = (FieldInfo)tInfo.vecFields.elementAt(i);
			strSQL += fInfo.strFieldName;
			strSQL += " ";
			strSQL += fInfo.strFieldType;
			strSQL += ")";
			System.out.println(strSQL);
			return strSQL;	
		}

               String ssupdate()
              {
                 int i = 0; 
                 String strSQL="insert into ";
			strSQL += tInfo.strTableName;
			strSQL +=" values('";      
		for(i=0; i<v.size()-1; i++)
			{	
				strSQL += (String)v.elementAt(i) + "','";	
			}
			strSQL += (String)v.elementAt(i);			
			strSQL += "')";
			System.out.println(strSQL);
			return strSQL;	
		}

		public static void main(String []args) throws Exception
		{	String driver ="sun.jdbc.odbc.JdbcOdbcDriver";
			String connStr="jdbc:odbc:mysource";
			Connection con=null;
			Class.forName(driver);
			con=DriverManager.getConnection(connStr);
                        Statement stm = con.createStatement();
			if(!con.isClosed())
				System.out.println("数据库连接成功");
                        int j = 0;
			String Msg;
			funcOper fun = new funcOper();
			BufferedReader fReader = new BufferedReader(new FileReader("d:\\jstudy\\Text.txt"));
			while((Msg= fReader.readLine())!=null)
                 	{j++;
			switch(j) {
				case 1:
					fun.setTableName(Msg); break;
				case 2:
					fun.setFieldName(Msg); break;
				case 3:
					fun.setFieldType(Msg); 
					String s = fun.getCreateTableSQL();
                                        stm.execute(s); break;  
                                case 4:
					fun.setInfomation(Msg);
					String t = fun.ssupdate();
					stm.executeUpdate(t);
					break; 			
                                		
				}				
			}
			stm.close();
			con.close();                    		
		}

} 


 

⌨️ 快捷键说明

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