Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #353 > unrolled thread
| Started by | "Yogi" <yogi@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:23 +0000 |
| Last post | 2011-04-27 15:23 +0000 |
| Articles | 7 — 2 participants |
Back to article view | Back to comp.lang.java.databases
Java Database connection "Yogi" <yogi@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: Java Database connect "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: Java Database connect "Yogi" <yogi@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: Java Database connect "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: Java Database connect "Yogi" <yogi@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: Java Database connect "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: Java Database connect "Yogi" <yogi@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
| From | "Yogi" <yogi@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Java Database connection |
| Message-ID | <caf6d8eb-ab35-4814-aece-e0b0bdebda83@a3g2000prm.googlegroups.com> |
To: comp.lang.java.databases
Hi,
I am new to java and db connection pooling. I tried using Apache's
DBCP for connection pool for my web application. Was trying to do
similar thing for a standalone server (not a web based). I tried
using DBCP but i am getting strange results. In my string variables,
i am getting "???" as output whereas for int variables i am getting
correct values when i m trying to read from database.
Here is the snippet code:
I have a package "com.engine". In this package,
1. I am having EngineDBConnection which is responsible to pool
connections.
2. "EngineDBManager" class takes care of process user's queries and
calls required procedures and db constructs
3. "Test" is the actual code which runs and gets required fields and
displays to client.
>>>>>>>>>>>>>.
package com.engine;
import org.apache.commons.dbcp.BasicDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class EngineDBConnection {
private static String dbURL = "jdbc:oracle:thin:user/pwd@localhost:
1521:orcl";
static DataSource dataSource = null;
public static void createDataSource(){
// create db connection in constructor
dataSource = setupDataSource(dbURL);
}
public static Connection getConnection() {
Connection conn = null;
try {
if (dataSource != null) {
conn = dataSource.getConnection();
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static DataSource setupDataSource(String connectURI) {
BasicDataSource ds = new BasicDataSource();
System.out.println("coming in setupdatasource");
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUsername("user");
ds.setPassword("pwd");
ds.setUrl(connectURI);
return ds;
}
public static void shutdownDataSource(DataSource ds) throws
SQLException {
BasicDataSource bds = (BasicDataSource) ds;
bds.close();
}
}
-------------------------
package com.engine;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import oracle.sql.STRUCT;
import com.dbobjs.DInfo;
public class EngineDBManager {
public static List<DInfo> getDInfo(){
Connection conn = null;
conn = EngineDBConnection.getConnection();
CallableStatement cst = null;
List<DInfo> dList = null;
int result = -9;
try{
cst = conn.prepareCall("begin pkg_admin.p_get_info(?,?);
end;");
cst.registerOutParameter(1, Types.ARRAY, "VARRAY_DINFO");
cst.registerOutParameter(2, Types.INTEGER);
cst.execute();
result = cst.getInt(2);
if (result != 0) {
return null;
}
Object structs[] = (Object[])(cst.getArray(1).getArray());
dList = new ArrayList<DInfo>(structs.length);
for (int i = 0; i < structs.length; i++) {
DInfo map = (DInfo)DInfo.readStruct((STRUCT)structs[i]);
dList.add(map);
}
cst.close();
conn.close();
}catch (Exception e) {
e.printStackTrace();
}
return dList;
}
}
-------------------------------
package com.engine;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import java.util.List;
import com.dbobjs.DInfo;
public class Test {
public Test(){
EngineDBConnection.createDataSource();
}
public static void main(String args[]){
Test t1 = new Test();
List <DInfo> dList = EngineDBManager.getDInfo();
DInfo d = null;
if (dList == null){
System.out.println("DInfo is null");
}else{
for (int i=0;i < dList.size(); i++){
d = (DInfo) dList.get(i);
System.out.println("Id=" + d.getDID() + " Desc=" +
dist.getDDesc());
}
}
}
>>>>>>>>>>>>>>>>>>>>>
when I am printing output in "Test" class, I am getting correct Id but
Desc is giving me "???". I tried executing oracle procedure from
oracle and it is working perfectly fine. Am i missing something
here? Please help.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Re: Java Database connect |
| Message-ID | <k92dnX3th-xVpLzUnZ2dnUVZ8judnZ2d@novis.pt> |
| In reply to | #353 |
To: comp.lang.java.databases Yogi wrote: > I am new to java and db connection pooling. I tried using Apache's > DBCP for connection pool for my web application. Was trying to do > similar thing for a standalone server (not a web based). I tried > using DBCP but i am getting strange results. In my string variables, > i am getting "???" as output whereas for int variables i am getting > correct values when i m trying to read from database. > Make sure you use the correct encoding when connecting to the databse, for example, UTF-8. Refer to the manual of the database and JDBC driver for specifics. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Yogi" <yogi@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Re: Java Database connect |
| Message-ID | <248e0824-2a28-44a6-bb47-5912813d5894@a3g2000prm.googlegroups.com> |
| In reply to | #354 |
To: comp.lang.java.databases On Nov 17, 2:30=A0pm, Sabine Dinis Blochberger <no.s...@here.invalid> wrote: > Yogi wrote: > > I am new to java and db connection pooling. I tried using Apache's > > DBCP for connection pool for my web application. =A0Was trying to do > > similar thing for a standalone server (not a web based). =A0I tried > > using DBCP but i am getting strange results. =A0In my string variables, > > i am getting "???" as output whereas for int variables i am getting > > correct values when i m trying to read from database. > > Make sure you use the correct encoding when connecting to the databse, > for example, UTF-8. Refer to the manual of the database and JDBC driver > for specifics. Thanks Sabine for your reply. I understand your point. But same DB and jdbc driver is working fine when i m hitting this db from web based application. There I am getting correct values. Anything specific to non-web based servers? --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Re: Java Database connect |
| Message-ID | <-Oqdnehdo6po_rzUnZ2dnUVZ8tzinZ2d@novis.pt> |
| In reply to | #355 |
To: comp.lang.java.databases Yogi wrote: > On Nov 17, 2:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> > wrote: > > Yogi wrote: > > > I am new to java and db connection pooling. I tried using Apache's > > > DBCP for connection pool for my web application. Was trying to do > > > similar thing for a standalone server (not a web based). I tried > > > using DBCP but i am getting strange results. In my string variables, > > > i am getting "???" as output whereas for int variables i am getting > > > correct values when i m trying to read from database. > > > > Make sure you use the correct encoding when connecting to the databse, > > for example, UTF-8. Refer to the manual of the database and JDBC driver > > for specifics. > > Thanks Sabine for your reply. I understand your point. But same DB > and jdbc driver is working fine when i m hitting this db from web > based application. There I am getting correct values. Anything > specific to non-web based servers? This could be only a display problem then - on your other environment you don't have the correct locales installed. You'll need to be more specific as to where and how you see the "???" in string values obtained from DB. If you write them into a file, and open that with something that can't display multi-byte characters, you might get question marks. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Yogi" <yogi@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Re: Java Database connect |
| Message-ID | <fa657270-2b6a-4416-a249-bef7c532c268@s1g2000prg.googlegroups.com> |
| In reply to | #356 |
To: comp.lang.java.databases On Nov 17, 5:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> wrote: > Yogi wrote: > > On Nov 17, 2:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> > > wrote: > > > Yogi wrote: > > > > I am new to java and db connection pooling. I tried using Apache's > > > > DBCP for connection pool for my web application. Was trying to do > > > > similar thing for a standalone server (not a web based). I tried > > > > using DBCP but i am getting strange results. In my string variables, > > > > i am getting "???" as output whereas for int variables i am getting > > > > correct values when i m trying to read from database. > > > > Make sure you use the correct encoding when connecting to the databse, > > > for example, UTF-8. Refer to the manual of the database and JDBC driver > > > for specifics. > > > Thanks Sabine for your reply. I understand your point. But same DB > > and jdbc driver is working fine when i m hitting this db from web > > based application. There I am getting correct values. Anything > > specific to non-web based servers? > > This could be only a display problem then - on your other environment > you don't have the correct locales installed. > > You'll need to be more specific as to where and how you see the "???" in > string values obtained from DB. > > If you write them into a file, and open that with something that can't > display multi-byte characters, you might get question marks. I am using Eclipse to execute my program and getting "???" in Eclipse's console. One of my friend suggested to check for dependent jars while using Apache's DBCP. But what I am bothered about is, if dependent jars are not available, it should not give me correct values for integer placeholders as well. Any comments? --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Sabine Dinis Blochberger" <sabine.dinis.blochberger@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Re: Java Database connect |
| Message-ID | <6PCdnXNrv4-597zUnZ2dnUVZ8v6dnZ2d@novis.pt> |
| In reply to | #357 |
To: comp.lang.java.databases Yogi wrote: > On Nov 17, 5:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> > wrote: > > Yogi wrote: > > > On Nov 17, 2:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> > > > wrote: > > > > Yogi wrote: > > > > > I am new to java and db connection pooling. I tried using Apache's > > > > > DBCP for connection pool for my web application. Was trying to do > > > > > similar thing for a standalone server (not a web based). I tried > > > > > using DBCP but i am getting strange results. In my string variables, > > > > > i am getting "???" as output whereas for int variables i am getting > > > > > correct values when i m trying to read from database. > > > > > > Make sure you use the correct encoding when connecting to the databse, > > > > for example, UTF-8. Refer to the manual of the database and JDBC driver > > > > for specifics. > > > > This could be only a display problem then - on your other environment > > you don't have the correct locales installed. > > > > I am using Eclipse to execute my program and getting "???" in > Eclipse's console. One of my friend suggested to check for dependent > jars while using Apache's DBCP. But what I am bothered about is, if > dependent jars are not available, it should not give me correct values > for integer placeholders as well. Any comments? If you were missing libraries, you would get an Exception telling you so. Ok, from the Javadocs [0]: "public void print(String s) Prints a string. If the argument is null then the string "null" is printed. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method. Parameters: s - The String to be printed" Instead of using System.out.println, use a logging facility? Or set your environments default character encoding to UTF-8 [1]? [0] <http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html#print(java.lang.String)> [1] <http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg07331.html> --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Yogi" <yogi@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:23 +0000 |
| Subject | Re: Java Database connect |
| Message-ID | <ad35b26f-2af8-47c5-b16c-ba89634083bb@d42g2000prb.googlegroups.com> |
| In reply to | #359 |
To: comp.lang.java.databases On Nov 17, 5:57 pm, Sabine Dinis Blochberger <no.s...@here.invalid> wrote: > Yogi wrote: > > On Nov 17, 5:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> > > wrote: > > > Yogi wrote: > > > > On Nov 17, 2:30 pm, Sabine Dinis Blochberger <no.s...@here.invalid> > > > > wrote: > > > > > Yogi wrote: > > > > > > I am new to java and db connection pooling. I tried using Apache's > > > > > > DBCP for connection pool for my web application. Was trying to do > > > > > > similar thing for a standalone server (not a web based). I tried > > > > > > using DBCP but i am getting strange results. In my string variables, > > > > > > i am getting "???" as output whereas for int variables i am getting > > > > > > correct values when i m trying to read from database. > > > > > > Make sure you use the correct encoding when connecting to the databse, > > > > > for example, UTF-8. Refer to the manual of the database and JDBC driver > > > > > for specifics. > > > > This could be only a display problem then - on your other environment > > > you don't have the correct locales installed. > > > I am using Eclipse to execute my program and getting "???" in > > Eclipse's console. One of my friend suggested to check for dependent > > jars while using Apache's DBCP. But what I am bothered about is, if > > dependent jars are not available, it should not give me correct values > > for integer placeholders as well. Any comments? > > If you were missing libraries, you would get an Exception telling you > so. > > Ok, from the Javadocs [0]: > > "public void print(String s) > Prints a string. If the argument is null then the string "null" is > printed. Otherwise, the string's characters are converted into bytes > according to the platform's default character encoding, and these bytes > are written in exactly the manner of the write(int) method. > > Parameters: > s - The String to be printed" > > Instead of using System.out.println, use a logging facility? > Or set your environments default character encoding to UTF-8 [1]? > > [0] > <http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html#print(...)> > > [1] <http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg07331.html> Ok. This might be one of the issues. I will check your solutions and will update you. Thanks a ton for your inputs. :) --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.databases
csiph-web