I understand that I'll get something like this if I tried a substring with an index greater than the length of the string. But in this case I'm not doing anything like that. Also what does the negative number mean?
I'm getting "Open DB:String index out of range: -10"
Here is my code...
Here is the SQLServerConn code:
I'm getting "Open DB:String index out of range: -10"
Here is my code...
Code:
try {
//
// Connect to SQL Server
//
conn = new SQLServerConn(server, port, username, password);
stmt = conn.SQLServerConnection().createStatement();
}
catch (Exception e) {
spResultText="Open DB:" + e.getMessage();
set(7,spResultText);
return;
}
Here is the SQLServerConn code:
Code:
public SQLServerConn() throws Exception {
connect(null, null, null, null);
}
public SQLServerConn(String server, String port, String username, String password) throws Exception {
connect(server, port, username, password);
}
private void connect(String srv, String pt, String usr, String pwd) throws Exception {
String port; // Port SQL Server is listening on
String host; // SQL Server host name or IP Address
String sqlUser; // SQL Server user name
String sqlPwd; // SQL Server password
String iSeriesJob; // iSeries Job Name
//
// If connection already there,
// (and not closed) bail out!
//
if (connSQLServer!=null) {
if(!connSQLServer.isClosed()) {
return;
}
}
// initialize the JDBC driver class
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// Connection properties are stored in /MAINSAVER folder
if (srv == null) {
ConnSettings msSettings=new ConnSettings("/mainsaver/SQLProperties.dat");
port=msSettings.getProperty("Port");
host=msSettings.getProperty("Host");
sqlUser=msSettings.getProperty("User");
sqlPwd=msSettings.getProperty("Password");
}
else {
port = pt;
host = srv;
sqlUser = usr;
sqlPwd = pwd;
}
try {
iSeriesJob=MSRPGNative.iSeriesJobName();
} catch(Exception e) {
iSeriesJob="SQLServer (unknown)";
}
String hostName; // Get Name of AS/400
hostName=InetAddress.getLocalHost().getHostName();
try {
connSQLServer = DriverManager.getConnection("jdbc:sqlserver:" +
"//"+host+":"+port+";" +
"User="+sqlUser+";"+
"Password="+sqlPwd+";"+
"ProgramName=SqlServer("+hostName+");"+
"Wsid="+iSeriesJob+";");
}
catch (Exception e) {
// Truncate unnecessary JDBC Message from SQL Server
// [SQL Server JDBC Driver], etc.
throw new Exception(e.getMessage().substring(43));
}
}