Friday, February 10, 2012

Connecting to SQL Server 2k using Thin drivers

Hi all,
I am new to java. I need to write an applet which takes input from user and
updates the database. I wrote a trusted applet but i was unable to access
network resources. Then i wrote thread inside an apllet which is working fine.
When I use JDBC-ODBC driver, its taking DSN from client machine and not from
server. Can i specify Server DSN?
When I use Thin Drivers, I am getting ClassNotFoundException in the
following line
Driver d =
(Driver)Class.forName("com.microsoft.jdbc.sqlserve r.SQLServerDriver").newInstance();
Here is my code, please let me know if anything is wrong
try {
Driver d =
(Driver)Class.forName("com.microsoft.jdbc.sqlserve r.SQLServerDriver").newInstance();
con =
DriverManager.getConnection("jdbc:microsoft:sqlser ver://wks01:1433";User=test;Password=pass");
}
catch(ClassNotFoundException e) { e.printStackTrace();}
catch(Exception e){ e.printStackTrace();}
finally {
try {
Statement stmt = con.createStatement();
stmt.executeUpdate("INSERT INTO lms " + "VALUES ('" + NewApplet.this.lmsVar
+ "')");
if(con != null)
con.close();
}
catch(Exception e) { }
}
Also, If i specify Database Server name as Server name will it resolve from
client
| Thread-Topic: Connecting to SQL Server 2k using Thin drivers
| thread-index: AcS2s/k6uARnoX50RGqx7t2nvEPbgw==
| X-WBNR-Posting-Host: 203.197.255.91
| From: "=?Utf-8?B?VWp3YWwgQyBSZWRkeQ==?=" <Ujwal C
Reddy@.discussions.microsoft.com>
| Subject: Connecting to SQL Server 2k using Thin drivers
| Date: Wed, 20 Oct 2004 07:49:17 -0700
| Lines: 41
| Message-ID: <F3C3AA2A-D44F-413B-9439-E4C1DACD1297@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.jdbcdriver
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.jdbcdriver:6408
| X-Tomcat-NG: microsoft.public.sqlserver.jdbcdriver
|
| Hi all,
|
| I am new to java. I need to write an applet which takes input from user
and
| updates the database. I wrote a trusted applet but i was unable to access
| network resources. Then i wrote thread inside an apllet which is working
fine.
|
| When I use JDBC-ODBC driver, its taking DSN from client machine and not
from
| server. Can i specify Server DSN?
|
| When I use Thin Drivers, I am getting ClassNotFoundException in the
| following line
|
| Driver d =
|
(Driver)Class.forName("com.microsoft.jdbc.sqlserve r.SQLServerDriver").newIns
tance();
|
| Here is my code, please let me know if anything is wrong
|
| try {
| Driver d =
|
(Driver)Class.forName("com.microsoft.jdbc.sqlserve r.SQLServerDriver").newIns
tance();
| con =
|
DriverManager.getConnection("jdbc:microsoft:sqlser ver://wks01:1433";User=tes
t;Password=pass");
| }
| catch(ClassNotFoundException e) { e.printStackTrace();}
| catch(Exception e){ e.printStackTrace();}
| finally {
| try {
| Statement stmt = con.createStatement();
| stmt.executeUpdate("INSERT INTO lms " + "VALUES ('" +
NewApplet.this.lmsVar
| + "')");
| if(con != null)
| con.close();
| }
| catch(Exception e) { }
| }
|
|
| Also, If i specify Database Server name as Server name will it resolve
from
| client
|
|
|
Hello,
Just to make sure we're on the same page, I'm assuming a "thin" JDBC driver
to mean a Type 4 driver. The Microsoft JDBC driver is one such driver.
For the ClassNotFoundException, you must ensure that the JDBC driver .jar
files are listed appropriately in your CLASSPATH environment variable or
properly specified in the "-cp" command line parameter of java.exe. The
server name used in the URL to make the connection will either specify the
database server name and instance port number OR the database server name
and SQL Server instance name:
jdbc:microsoft:sqlserver://dbserver\\instance1;User=test;Password=pass;
jdbc:microsoft:sqlserver://dbserver:1456;User=test;Password=pass;
If the SQL Server instance is a default instance, then you can simply use
port 1433 (unless you have changed this default value explicitly) as you
have indicated in your sample above.
Hope that helps!
Carb Simien, MCSE MCDBA MCAD
Microsoft Developer Support - Web Data
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

No comments:

Post a Comment