📄 logon.java
字号:
package com.hnjchina.securityView;
import java.net.InetAddress;
import java.sql.*;
import java.util.*;
import com.sybase.jdbc2.jdbc.*;
/**
* @author limeiyong
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Logon {
private Connection mdbMaster = null;
private String msDbName = "heng_ngai";
private String msPassword = "Enterprise";
private String msPortNo = "5000";
private String msProtocol = "jdbc:sybase:Tds";
private String msServerName = "dbserver.hnjchina.com";
private String msUserid = "sa";
public ResultSet resultset = null;
private Statement stmt = null;
public int CloseAll() {
if (mdbMaster != null) {
try {
mdbMaster.close();
} catch (SQLException e1) {
// e1.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e1) {
// e1.printStackTrace();
}
}
if (resultset != null) {
try {
resultset.close();
} catch (SQLException e1) {
// e1.printStackTrace();
}
}
return 1;
}
public ResultSet exesql(String stringSql) {
boolean status = false, isLast = false;
int li_cnt = 0;
resultset = null;
if (mdbMaster == null) {
openDatabase();
}
try {
stmt = mdbMaster.createStatement();
resultset=stmt.executeQuery(stringSql);
} catch (SQLException e) {
System.out.println("logon to exesql SQLException error: " + e);
}
return resultset;
}
public void Listalltablename() {
try {
DatabaseMetaData dbmd = mdbMaster.getMetaData();
String[] types = {"TABLE"};
resultset = dbmd.getTables(null, null, "%", types);
while (resultset.next()) {
String tablename = resultset.getString(3);
String tablecatalog = resultset.getString(1);
String tableschema = resultset.getString(2);
System.out.println("tablename : " + tablename
+ " tablecatalog : " + tablecatalog + "tableschema : "
+ tableschema);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
// public int openDatabase() {
// String ls_URL,ls_driverName = null;
// Properties prop;
// SybDriver sybdrv;
// InetAddress host;
// try {
// ls_driverName="com.sybase.jdbcx.SybDriver";
// sybdrv = (SybDriver) Class.forName(ls_driverName).newInstance();
//// ls_driverName="com.inet.syb.SybDriver";
//// sybdrv = (SybDriver) Class.forName(ls_driverName).newInstance();
// } catch (Exception ex41) {
// if (ex41 instanceof InstantiationException
// || ex41 instanceof ClassNotFoundException) {
// try {
// ls_driverName="com.sybase.jdbc2.jdbc.SybDriver";
// sybdrv = (SybDriver) Class.forName
//
//(ls_driverName).newInstance();
// } catch (Exception ex52) {
// System.out.println("Can not Load Driver for Sybase::"
// + ex52.toString());
// return -1;
// }
// }
// }
// ls_URL = msProtocol + ":" + msServerName + ":" + msPortNo + "/"
// + msDbName;
// try {
// prop = new Properties();
// prop.put("user", msUserid);
// prop.put("password", msPassword);
// host = InetAddress.getLocalHost();
// prop.put("HOSTNAME", System.getProperty("user.name") + "@"
// + host.toString());
// mdbMaster = DriverManager.getConnection(ls_URL, prop);
// } catch (Exception eConnectionError) {
// System.out.println("Connection Error:"+ eConnectionError.toString());
// return -1;
// }
// return 1;
// }
public int openDatabase() {
String ls_URL,ls_driverName = null;
Properties prop;
SybDriver sybdrv;
InetAddress host;
try {
// Adaptive Server Anywhere 7.0
ls_driverName="sun.jdbc.odbc.JdbcOdbcDriver";
ls_URL = "jdbc:odbc:driver={Adaptive Server Anywhere 7.0};DBQ=security.db";
//// Microsoft SQL Server
// ls_driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
// ls_URL = "jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=simmay;DatabaseName=security";
//// sybase
// ls_driverName="com.sybase.jdbc2.jdbc.SybDriver";
// ls_URL = "jdbc:sybase:Tds:fileserver.hnjchina.com:5000/cstbld";
Class.forName(ls_driverName);
mdbMaster =DriverManager.getConnection(ls_URL,"dba","sql");
dbmd();
} catch (Exception ex41) {
System.out.println("Can not Load Driver for Sybase::"+ex41.toString());
return -1;
}
return 1;
}
public Connection getConnection(){
if (mdbMaster==null) openDatabase();
return mdbMaster;
}
public void dbmd(){
String[] types={"TABLE"};
try {
DatabaseMetaData md=mdbMaster.getMetaData();
ResultSet rs=md.getTables("",null,"%",types);
System.out.println("DriverName"+md.getNumericFunctions());
while (rs.next()){
System.out.println("Table1 "+rs.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -