1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| static Connection ConnectServer( String wsLogin, String wsPassword, String wsDatabaseFullPathName) throws SQLException
{
long ErrorCode = 0;
if( ErrorCode == 0)
{
// Provider=SQLNCLI11;User Instance=true;MARS Connection=true;AttachDbFilename=C:\\Programmes\\Microsoft SQLServer\\MSSQL10_50.SQLEXPRESS\\MSSQL\\DATA\\Coherence.mdf;Driver={SQL Server Native Client 11.0};Initial Catalog=Northwind
try
{
// Chargement du pilote JDBC
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" ).newInstance();
//"Integrated Security=true;Pooling=true;Max Pool Size=100;Timeout=15;MultipleActiveResultSets=true;Type System Version=SQL Server 2014;database=COHERENCE;server=xantia\\SQLEXPRESS"
Properties props = new Properties();
props.setProperty( "Initial Catalog", "Northwind");
props.setProperty( "Auto Reconnect", "true");
props.setProperty( "AttachDbFilename", "C:\\Programmes\\Microsoft SQL Server\\MSSQL12.SQLEXPRESS\\MSSQL\\DATA\\Coherence.mdf");
props.setProperty( "Type System Version", "SQL Server 2014");
props.setProperty( "Pooling", "true");
props.setProperty( "MaxPoolSize", "100");
props.setProperty( "MultipleActiveResultSets", "true");
props.setProperty( "Timeout", "15");
//props.setProperty( "Driver", "Microsoft SQL Server Express Edition (64-bit)");
//props.setProperty( "Driver Version", "12.0.2000 RTM");
props.setProperty( "databaseName", "Coherence");
props.setProperty( "integratedSecurity", "true");
props.setProperty( "instance","Xantia\\SQLEXPRESS");
props.setProperty( "user","XANTIA\\JeanNoël");
// URL de connexion
String url = "jdbc:odbc:login_DSN";
connection = DriverManager.getConnection( url, props);
stmt = connection.createStatement();
Data.m_bServerConnected = true;
}
catch( Exception ex)
{
ex.printStackTrace();
Data.m_bServerConnected = false;
}
finally
{
}
}
return( connection);
//OD
}
static int ExecuteSelectRequest( String wsRequest) throws SQLException
{
int iNbResultFound = 0;
String Result;
String stream;
boolean Status;
// IF myConnection" is not NULL) THEN
if( stmt == null)
{
connection = ConnectServer( "", "", "");
stmt = connection.createStatement();
}
//
try
{
stmt.execute( wsRequest);
myReader = stmt.getResultSet();
}
catch( Exception ex)
{
ex.printStackTrace();
Status = false;
}
return( iNbResultFound);
}
} |
Partager