?? sqlserver.java
字號(hào):
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);}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -