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

📄 adaptoramin.java

📁 数据库通用适配器:实现行粒度的数据库的转换
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			public void widgetSelected(SelectionEvent event){ 
				TableItem[] items =table.getItems();
				int radio=0,loctor=0,had=0;
				final Vector comb=new Vector();
				String SK ;
				String DK ;
				String SDriver;
				String DDriver;
				
				for(int i=0;i<items.length;i++)
				{
					if(items[i].getChecked()){radio++;loctor=i;}
				}	
				if(radio==1){
					
					final Shell Dialogshell = new Shell();
					Dialogshell.setVisible(false);
					Dialogshell.setSize(654, 419);
					Dialogshell.setText("方案配置");
					
					final int  point_x=(kit.getScreenSize().width - 654) / 2;
					final int  point_y=(kit.getScreenSize().height - 419) / 2;
					Dialogshell.setLocation(point_x, point_y);
					
					final Composite Dialogcomposite = new Composite(Dialogshell, SWT.NONE);
					Dialogcomposite.setBounds(0, 0, 629, 379);
					

					final Composite Dialogcomposite_1 = new Composite(Dialogcomposite, SWT.NONE);
					Dialogcomposite_1.setBounds(337, 0, 287, 223);
					
					Group Dialoggroup1=new Group(Dialogcomposite_1,SWT.NONE); //创建分组框
					Dialoggroup1.setText("任务周期"); //设置分组框说明信息
					Dialoggroup1.setBounds(5,2,282,216);

					final Button Dialogbutton_2 = new Button(Dialoggroup1, SWT.RADIO);
					Dialogbutton_2.setText("每月");
					Dialogbutton_2.setBounds(23, 52, 54, 16);
					

					final Button Dialogbutton_3 = new Button(Dialoggroup1, SWT.RADIO);
					Dialogbutton_3.setText("每周");
					Dialogbutton_3.setBounds(23, 84, 54, 16);
					
				
					final Button Dialogbutton_4 = new Button(Dialoggroup1, SWT.RADIO);
					Dialogbutton_4.setText("每天");
					Dialogbutton_4.setBounds(23, 120, 62, 16);
					Dialogbutton_4.setSelection(true);

					
					
					
					final Table Dialogtable_1 = new Table(Dialoggroup1, SWT.CHECK);
					Dialogtable_1.setBounds(91, 26,180, 153);
					Dialogtable_1.setLinesVisible(true);
					Dialogtable_1.setHeaderVisible(true);

					final TableColumn DialognewColumnTableColumn_2 = new TableColumn(Dialogtable_1, SWT.NONE);
					DialognewColumnTableColumn_2.setWidth(180);
					DialognewColumnTableColumn_2.setText("启动时间");

					final Button Dialogbutton_1 = new Button(Dialoggroup1, SWT.NONE);
					Dialogbutton_1.setBounds(110, 185,75, 22);
					Dialogbutton_1.setText("添加时间");
					
					final Button Dialogbutton_1_1 = new Button(Dialoggroup1, SWT.NONE);
					Dialogbutton_1_1.setBounds(190, 185,75, 22);
					Dialogbutton_1_1.setText("删除时间");

					final Composite Dialogcomposite_2 = new Composite(Dialogcomposite, SWT.NONE);
					Dialogcomposite_2.setBounds(337, 229, 287, 146);

					final Group ssGroup = new Group(Dialogcomposite_2, SWT.NONE);
					ssGroup.setText("导入方式");
					ssGroup.setBounds(5, 0, 277, 142);

					final Label Dialoglabel = new Label(ssGroup, SWT.NONE);
					Dialoglabel.setBounds(10, 35,43, 22);
					Dialoglabel.setText("条件:");

					final Text Dialogtext = new Text(ssGroup, SWT.BORDER);
					Dialogtext.setBounds(55, 35,201, 22);
					
					final Button tingyong1Button = new Button(ssGroup, SWT.CHECK);
					tingyong1Button.setBounds(10, 102,93, 16);
					tingyong1Button.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(final SelectionEvent e) {
						}
					});
					tingyong1Button.setText("停用");
					tingyong1Button.setSelection(true);

					final Button Dialogbutton_11 = new Button(ssGroup, SWT.NONE);
					Dialogbutton_11.setBounds(140, 99,48, 22);
					Dialogbutton_11.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(final SelectionEvent e) {
						}
					});
					Dialogbutton_11.setText("确定");

					final Button Dialogbutton_11_1 = new Button(ssGroup, SWT.NONE);
					Dialogbutton_11_1.setBounds(208, 99,48, 22);
					Dialogbutton_11_1.setText("取消");

					final Button Dialogbutton_10 = new Button(ssGroup, SWT.RADIO);
					Dialogbutton_10.setBounds(200, 75,56, 16);
					Dialogbutton_10.setText("创建表");

					final Button Dialogbutton_9 = new Button(ssGroup, SWT.RADIO);
					Dialogbutton_9.setBounds(140, 75,52, 16);
					Dialogbutton_9.setText("添加");

					final Button Dialogbutton_8 = new Button(ssGroup, SWT.RADIO);
					Dialogbutton_8.setBounds(80, 75,52, 16);
					Dialogbutton_8.setText("更新");
					Dialogbutton_8.setSelection(true);

					final Group ddGroup = new Group(Dialogcomposite, SWT.NONE);
					ddGroup.setBounds(5, 2,324, 369);
					ddGroup.setText("字段映射");
					
					final Combo Dialogcombo = new Combo(ddGroup, SWT.NONE);
					Dialogcombo.setBounds(5, 17,150, 25);

					final Combo Dialogcombo_1 = new Combo(ddGroup, SWT.NONE);
					Dialogcombo_1.setBounds(155, 17,150, 25);

					final Table Dialogtable = new Table(ddGroup, SWT.CHECK);
					Dialogtable.setBounds(5, 45,300, 286);
					Dialogtable.setLinesVisible(true);
					Dialogtable.setHeaderVisible(true);

					final TableColumn DialognewColumnTableColumn = new TableColumn(Dialogtable, SWT.CENTER);
					DialognewColumnTableColumn.setAlignment(SWT.CENTER);
					DialognewColumnTableColumn.setWidth(150);
					DialognewColumnTableColumn.setText("源数据库表字段");

					final TableColumn DialognewColumnTableColumn_1 = new TableColumn(Dialogtable, SWT.NONE);
					DialognewColumnTableColumn_1.setWidth(150);
					DialognewColumnTableColumn_1.setText("目的数据库表字段");

					final Button Dialogbutton = new Button(ddGroup, SWT.NONE);
					Dialogbutton.setBounds(155, 340,68, 22);
					Dialogbutton.setText("添加映射");
					
					final Button Dialogbutton_12 = new Button(ddGroup, SWT.NONE);
					Dialogbutton_12.setBounds(225, 340,68, 22);
					Dialogbutton_12.setText("删除映射");
					
				
					
					Dialogshell.layout();
					
					String TableName1,TableName2;
					TableName1=((CCombo)comb3.elementAt(loctor)).getText();
					TableName2=((CCombo)comb4.elementAt(loctor)).getText();			
					
					String columnName1[];
					String columnName2[];
					String columnType1[],columnType2[];
					
					final Vector DType=new Vector();
					
					Dialogbutton_11_1.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(final SelectionEvent e) {
							Dialogshell.close();
						}
					}
					);
					Dialogbutton_12.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(final SelectionEvent e) {
							TableItem[] ite=Dialogtable.getItems();
			        		for(int i=0;i<ite.length;i++)
			        		{
			        			if(!ite[i].getChecked())continue;
			        			int index=Dialogtable.indexOf(ite[i]);
			        			if(index<0)continue;
			        			Dialogtable.remove(index); 
			    			}
						}
					});
					
					Dialogbutton_1_1.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(final SelectionEvent e) {
							TableItem[] ite_1=Dialogtable_1.getItems();
			        		for(int i=0;i<ite_1.length;i++)
			        		{
			        			if(!ite_1[i].getChecked())continue;
			        			int index=Dialogtable_1.indexOf(ite_1[i]);
			        			if(index<0)continue;
			        			Dialogtable_1.remove(index); 
			    			}
						}
					});
					
					if((!((CCombo)comb1.elementAt(loctor)).getText().equals(""))&&(!((CCombo)comb2.elementAt(loctor)).getText().equals(""))){
						int size=0;			
	        			for(int i=0;i<S.getS().size();i++){	 
	        				
	        				if(((CCombo)comb1.elementAt(loctor)).getText().equals(((Source)S.getS().elementAt(i)).getDateName())){ 
	        					    if(((Source)S.getS().elementAt(i)).getType().equals("Excel")){
	        					    	SK="Excel";
	        					    		  HSSFWorkbook workbook;
											try {
												workbook = new HSSFWorkbook(new FileInputStream(((Source)S.getS().elementAt(i)).getConnURL()));
												 HSSFSheet sheet = workbook.getSheet("sheet1");
												 
												 int initRow = 0;
												 int rows = sheet.getPhysicalNumberOfRows(); 
												 for (int r = 0; r < rows; r++) 
												 { 
												 HSSFRow row = sheet.getRow(r); 
												 if (row != null)
												 { 
													 initRow=r;
													 break;
												 }
												 }
												 HSSFRow FirstRow = sheet.getRow(initRow);
												 int Colnum=FirstRow.getPhysicalNumberOfCells();
												 System.out.println(Colnum); 
												 columnName1=new String[Colnum];
												 columnType1=new String[Colnum];

												 for (int c = 0; c < Colnum; c++) 
												 { 
												 HSSFCell cell = FirstRow.getCell(c); 
												 if (cell != null) 
												 { 
												 switch (cell.getCellType()) 
												 { 
												 case HSSFCell.CELL_TYPE_FORMULA : 
												      columnName1[c]=""+cell.getNumericCellValue();
												      break; 
												 case HSSFCell.CELL_TYPE_NUMERIC: 
													 columnName1[c]=""+cell.getNumericCellValue();
												      break; 
												 case HSSFCell.CELL_TYPE_STRING: 
													 columnName1[c]=cell.getStringCellValue();
												      break; 
												 default: 
												 } 
												 }
												 
												 }
												 HSSFRow secondRow = sheet.getRow(initRow+1);
												 for (int c = 0; c < Colnum; c++) 
												 { 
												 HSSFCell cell = secondRow.getCell(c); 
												 if (cell != null) 
												 { 
												 switch (cell.getCellType()) 
												 { 
												 case HSSFCell.CELL_TYPE_FORMULA : 
													 columnType1[c]="NUMBER";
												      break; 
												 case HSSFCell.CELL_TYPE_NUMERIC: 
													 columnType1[c]="NUMBER";
												      break; 
												 case HSSFCell.CELL_TYPE_STRING: 
													 columnType1[c]="VARCHAR2";
												      break; 
												 default: 
												 } 
												 } 												 
												 }	
												 for (int c = 0; c < Colnum; c++) 
												 {
													 Dialogcombo.add(columnName1[c]+"("+columnType1[c]+")");
												 }
												 for(int k=0;k<Colnum;k++) System.out.println(columnName1[k]+" "+columnType1[k]);
											 
											} catch (FileNotFoundException e) {
												// TODO Auto-generated catch block
												e.printStackTrace();
											} catch (IOException e) {
												// TODO Auto-generated catch block
												e.printStackTrace();
											}
	        					  			 
	        					  		 
	        					    }else{
	        						try {
	        							Class.forName(((Source)S.getS().elementAt(i)).getDriver());
	        							String schema1=((Source)S.getS().elementAt(i)).getSchema();
	        							System.out.println(""+((Source)S.getS().elementAt(i)).getConnURL()+((Source)S.getS().elementAt(i)).getUseName()+((Source)S.getS().elementAt(i)).getPassword());
	        							Connection con=DriverManager.getConnection(((Source)S.getS().elementAt(i)).getConnURL(),
												((Source)S.getS().elementAt(i)).getUseName(),((Source)S.getS().elementAt(i)).getPassword());
                                        SK=((Source)S.getS().elementAt(i)).getType();
                                        SDriver=((Source)S.getS().elementAt(i)).getDriver();
	        							Statement stmt=con.createStatement();
										DatabaseMetaData m_DBMetaData =con.getMetaData();
										ResultSet rs=m_DBMetaData.getColumns(null,schema1, TableName1,"%");										
										while(rs.next()){size++;}										
										System.out.println("rs:"+size);
										columnName1=new String[size];
										columnType1=new String[size];
									
										int k=0;
										rs=m_DBMetaData.getColumns(null,schema1, TableName1,"%");
										while(rs.next()){
											columnName1[k] = rs.getString("COLUMN_NAME");
											
											columnType1[k] = rs.getString("TYPE_NAME");
											
											System.out.println(columnName1[k]+" "+columnType1[k]);
											 Dialogcombo.add(columnName1[k]+"("+columnType1[k]+")");
											k++;								
										}						
									
								
										System.out.println("");												
										rs.close();
										//stmt.close();												
										con.close();
									} catch (SQLException e) {
										// TODO Auto-generated catch block
										e.printStackTrace();

⌨️ 快捷键说明

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