|
Home > Archive > SQL Server JDBC > August 2005 > JDBC driver conflict with "System.in.read();"?????????????
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
JDBC driver conflict with "System.in.read();"?????????????
|
|
| googou 2005-08-10, 3:23 am |
| Hi;
I'm writing a application which access the SQL SERVER 2000 by "SQL
SERVER Driver for JDBC SP3".
I create a thread class to fecth data from database,code like blow:
public class DBThread extends Thread{
public void run(){
Connection conn = null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn =
DriverManager.getConnection(" jdbc:microsoft:sqlse
rver:// localhost:1433;Datab
aseName=Test","sa","sa");
Statement statement = conn.createStatement();
//do stg......
}catch(Exception ex){
ex.printStackTrace();
}
}
}
Another class DBTest as the Main class ,to create the DBthread and start
it.code like below:
public class DBTest {
public static void main(String[] args) {
try{
System.out.println("begin");
DBThread dt = new DBThread();
dt.start();
System.in.read();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
When i start the application, I find that the DBThread can not fetch the
data from db,it is blocked at the line "conn =
DriverManager.getConnection......" until the main thread receive a char to
end.
I make tests with other drivers,the DBThread can work well.
If i replace the "System.in.read();" with a long time loop or another block
code such as "Object.wait()",the DBThread can work well too.
I can not find any connecttion between the "DriverManager.getConnection..."
and "System.in.read()",
How can i solve the problem?Is this a BUG in JDBC?????????
Thanks!
googou
| |
| joeNOSPAM@bea.com 2005-08-10, 8:23 pm |
| Hi. I am not sure what's wrong, but I tried to duplicate your problem
with a simple single program, and couldn't.
Joe Weinstein at BEA Systems
/*
when I run this, I get:
C:\new_ms_driver>java foo
begin
input?
DBThread started
Driver version is 1.0.107.104
Database Major version is 8
Database Minor version is 0
DBThread done
(I type in something now)
*/
import java.sql.*;
import java.util.*;
public class foo
{
public static void main(String args[])
throws Exception
{
try{
System.out.println("begin");
DBThread dt = new DBThread();
dt.start();
System.out.println("input?");
System.in.read();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
class DBThread extends Thread{
public void run(){
Connection c = null;
try
{
System.out.println("DBThread started");
Properties props = new Properties();
Driver d = new
com.microsoft.sqlserver.jdbc.SQLServerDriver();
props.put("user", "joe");
props.put("password", "joe");
c = d.connect("jdbc:sqlserver://joe:1433", props );
DatabaseMetaData dd = c.getMetaData();
System.out.println("Driver version is " +
dd.getDriverVersion() );
System.out.println("Database Major version is " +
dd. getDatabaseMajorVers
ion() );
System.out.println("Database Minor version is " +
dd. getDatabaseMinorVers
ion() );
}
catch (Exception ouch)
{
System.out.println("ouch: " + ouch );
}
System.out.println("DBThread done");
}
}
| |
| googou 2005-08-10, 8:23 pm |
| Thanks for your help!
I do it as you,there are no problem too.So i realize what is the reason
suddenly,i start the application in IDE not the command line when it goes
wrong. I use Eclipse platform as my java IDE,this maybe the bug of Eclipse.
"joeNOSPAM@bea.com" wrote:
> Hi. I am not sure what's wrong, but I tried to duplicate your problem
> with a simple single program, and couldn't.
>
> Joe Weinstein at BEA Systems
>
> /*
> when I run this, I get:
>
> C:\new_ms_driver>java foo
> begin
> input?
> DBThread started
> Driver version is 1.0.107.104
> Database Major version is 8
> Database Minor version is 0
> DBThread done
> (I type in something now)
> */
>
> import java.sql.*;
> import java.util.*;
>
> public class foo
> {
> public static void main(String args[])
> throws Exception
> {
> try{
> System.out.println("begin");
> DBThread dt = new DBThread();
> dt.start();
> System.out.println("input?");
> System.in.read();
> }catch(Exception ex){
> ex.printStackTrace();
> }
> }
> }
>
> class DBThread extends Thread{
> public void run(){
> Connection c = null;
> try
> {
> System.out.println("DBThread started");
> Properties props = new Properties();
> Driver d = new
> com.microsoft.sqlserver.jdbc.SQLServerDriver();
>
> props.put("user", "joe");
> props.put("password", "joe");
>
> c = d.connect("jdbc:sqlserver://joe:1433", props );
>
> DatabaseMetaData dd = c.getMetaData();
> System.out.println("Driver version is " +
> dd.getDriverVersion() );
> System.out.println("Database Major version is " +
> dd. getDatabaseMajorVers
ion() );
> System.out.println("Database Minor version is " +
> dd. getDatabaseMinorVers
ion() );
> }
> catch (Exception ouch)
> {
> System.out.println("ouch: " + ouch );
> }
> System.out.println("DBThread done");
> }
> }
>
>
|
|
|
|
|