on 11-22-2006 12:48 PM
Hi,
I am trying to connect to SQL Plus.
ClassName, DriverType,Host,Port,DataBaseName,userName, Password are all String types.
Class.forName(ClassName);
final String OracleUrl = DriverType + "@" + Host + ":" + Port + ":"
+ DataBaseName;
Connection objCon = DriverManager.getConnection(OracleUrl, userName, password);
I have given all values except DataBaseName. Where can I find the DataBaseName which I am using? Actually I am using simple select query to retrieve one value from emp table(default).
Kindly help me out.
Kalai.
Message was edited by:
Kalaivani Pachiappan
Hi,
Before doing this,check the connection is it working fine or not.
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://Server:Host;user=UserName;password=Password;database=DBUser");
Otherwise You can Create a Data Source alias name and connect the Database
InitialContext initialContext = new InitialContext();
DataSource dataSource = (DataSource)initialContext.lookup("jdbc/DataSource");
java.sql.Connection conn = dataSource.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
String strName = null;
while (rs.next()) {
strName = rs.getString(2);
WdComp[onentAPI.getMessageManager().reportSuccess(strName);
}
// follow this also
you can create DataSource in SAP J2EE Engine through Visual Administrator , corresponding to this data base.
(have to create one alias wr this data source)
then you can look up this alias name wr2 ur RDBMS from WebDynpro code itself ,
create connection
and query data base tables.
that RDBMS must have driver ..
depending upon the data base driver u have to create drivers in J2EE Engine.
for eg..
Create SQL server 2000 JDBC 2.0 driver in j2ee engine
Download SQL Server 2000 Driver for JDBC Service Pack 3: (http://www.microsoft.com/downloads/details.aspx?familyid=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en) and install it on j2ee server.
Open Visual administrator, /usr/sap/<instance name>/JC00/j2ee/admin/go.bat
Navigate to server > services > JDBC connector > drivers in runtime tab
Click create new driver and specify a name, eg SQL Server)
Point to 3 .jar files which was installed by the MS jdbc driver before. The files are: msbase.jar, mssqlserver.jar and msutil.jar
The driver installation is now completed
Create datasource
Click DataSources in the same path as above (server > services > JDBC connector)
Click new driver or datasource.
Fillout the following properties:
o Main tab > DataSource Name: fx MyDatasource
o Main tab > Add Alias: fx MyAlias
o Main tab > Driver Name: SQL Server
o Main tab > JDBC version: 2.0 (with XA support)
o Main tab > Object factory: com.microsoft.jdbcx.sqlserver.SQLServerDataSourceFactory
o Main tab > DataSource Type: ConnectionPoolDataSource
o Main tab > CPDS classname: com.microsoft.jdbcx.sqlserver.SQLServerDataSource
o Additional tab > add property serverName = <your server>, fx localhost
o Additional tab > add property databaseName = <your db>, fx Northwind
o Additional tab > add property portNumber = <port>, fx 1433
o Additional tab > add property user = <sql database user>, fx sa
o Additional tab > add property password = <password>
Save and restart J2EE. The datasource is now ready to use.
Try like this.
It might helps you.
Thanks,
Lohi.
Message was edited by:
Lohitha M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lohitha,
I need to connect to SQL Plus. For that how can I code?? or for that how can I create datasource. What is that jdbc/DataSource in lookup refers to? How can I get that value?? What is the use of that lookup??
DataSource dataSource = (DataSource)initialContext.lookup("jdbc/DataSource");
Regards,
Kalai.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.