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

📄 sqlserver.java

📁 This is source rmi with java
💻 JAVA
字号:
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
import java.net.*;
import java.io.*;
import java.util.*;

public class SQLServer extends UnicastRemoteObject implements SQLInterface
{
	Vector vecData=new Vector();
	String rowDatas[][];
	String nameColumns[];
	String error="";
	String resultUpdate="";

  public SQLServer() throws RemoteException
	{
		super();
	}
  public void exeScript(String strRead) throws RemoteException
    {
  	  String strReadLine[]=strRead.split("\n");
  	  try
	   {
		  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		  Connection cn=DriverManager.getConnection("jdbc:odbc:thuanSQL");
		  Statement st=cn.createStatement();
		  try
		    {
			  st.clearBatch();
			  for(int i=0;i<strReadLine.length;i++)
			    { st.addBatch(strReadLine[i]);}
			  error="";
			}
		   catch(Exception e){error=e.toString();}
		   int r[]=st.executeBatch();
		   st.close();cn.close();
		 }
		 catch(Exception e)
		 {
			error=e.toString();System.out.println("loi chay script"+e);
		 }
	 }
  public void exeSelect(String strSelect) throws RemoteException
	 {
	   try
	    {
		   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		   Connection cn=DriverManager.getConnection("jdbc:odbc:thuanSQL");
		   Statement st1=cn.createStatement();
		   ResultSet rest=st1.executeQuery(strSelect);
		   ResultSetMetaData rsmd = rest.getMetaData();
		   int numberOfColumns = rsmd.getColumnCount();
		   int numberOfRows=0;
           nameColumns=new String[numberOfColumns];
		   for(int i=1;i<=numberOfColumns;i++)
		      {
		        nameColumns[i-1]=rsmd.getColumnName(i);
		      }
		   while(rest.next())
		     {
		       for(int j=1;j<=numberOfColumns;j++)
		           {
		             vecData.addElement(rest.getString(j));
		           }
		       numberOfRows=rest.getRow();
		     }
		 int add=0;
		 rowDatas=new String[numberOfRows][numberOfColumns];
		 for(int i=0;i<numberOfRows;i++)
		   {
		     for(int j=0;j<numberOfColumns;j++)
		       {
	    	      rowDatas[i][j]=vecData.elementAt(add+j).toString();
	    	   }
		    add+=numberOfColumns;
		   }
	    vecData.removeAllElements();
		st1.close();cn.close();error="";
	 }
   catch(Exception e)
    { error="loi chay tren server"+e.toString();}
  }
 public String getError() throws RemoteException { return error;}
 public void exeUpdate(String strUpdate) throws RemoteException
  {
    try
  	 {
  	   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  	   Connection c=DriverManager.getConnection("jdbc:odbc:thuanSQL");
  	   Statement sUpdate=c.createStatement();
  	   int result=sUpdate.executeUpdate(strUpdate);

       if(result==0){resultUpdate="You are not successful!";}
  	   else{resultUpdate="You are successful!";}
  	   error="";
  	 }
  	catch(Exception e){error=e.toString();}
 }
 public String[][] getRowData() throws RemoteException
 {
	 return rowDatas;
 }
 public String[] getNameColumn() throws RemoteException
 {
	 return nameColumns;
 }
 public String getResultUpdate() throws RemoteException
 {
	 return resultUpdate;
 }
 public static void main(String arg[])
 {
	 //System.setSecurityManager(new RMISecurityManager());
	 InetAddress thisComputer;
	 try
	  {
     	 thisComputer=InetAddress.getLocalHost();
     	 SQLServer instance=new SQLServer();
     	 try
		  {
		    Naming.rebind("//localhost"+"/SQLInterface",instance);
		    System.out.println("Yes I am registered !");
		  }
         catch(Exception e){System.out.println(e);}
	  }
	 catch(Exception e) {System.out.println(e);}
 }
}

⌨️ 快捷键说明

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