on 11-20-2006 11:45 AM
Hi,
I have created an application, where i have a separate java file for connecting JDBC. I am trying to retrieve a value from a table (with a simple select statement). I have written that code in Component Controller. The value is not getting retrieved in the context. What could be the problem?
ConnectionHolder objHolder = new ConnectionHolder();
Connection con = objHolder.getConnection();
PreparedStatement pstt = con.prepareStatement("select name from emp where id = 18");
ResultSet rs;
String strName = null;
rs = pstt.executeQuery();
while (rs.next()) {
strName = rs.getString(2);
}
wdContext.currentContextElement().setEmpId(strName);
Kindly help me out. Is there any wrong in my code?
Thanks & Regards,
Dhana
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);
}
Disply first the str and make it map to context.
Try like this.
It might helps you.
Thanks,
Lohi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please let us know the exception.
First check the mappings from componentController to your view.
try configuring the datasource in JDBC services of visualadministrator and use the following
try{
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/Anil");
con = ds.getConnection();
PreparedStatement pstt = con.prepareStatement("select name from emp where id = 18");
ResultSet rs;
String strName = null;
rs = pstt.executeQuery();
while (rs.next()) {
strName = rs.getString(2);
}catch(Exception e){
}
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.