Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Tuesday, March 27, 2012

connecting to SQL Server 2000 using JDBC

I've download Microsoft SQL Server 2000 JDBC Driver. All these files are being installed and saved in a folder called sql. For example, the IP adress is 255.255.255.255 , I updated the code and saved it as test1.java in this manner:

import java.sql.*;
/**
* Microsoft SQL Server JDBC test program
*/
public class test1 {
public test1() throws Exception {
// Get connection
DriverManager.registerDriver(new
com.microsoft.jdbc.sqlserver.SQLServerDriver());
Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver:@.255.255.255","abc","abc");
if (connection != null) {
System.out.println();
System.out.println("Successfully connected");
System.out.println();
// Meta data
DatabaseMetaData meta = connection.getMetaData();
System.out.println("\nDriver Information");
System.out.println("Driver Name: "
+ meta.getDriverName());
System.out.println("Driver Version: "
+ meta.getDriverVersion());
System.out.println("\nDatabase Information ");
System.out.println("Database Name: "
+ meta.getDatabaseProductName());
System.out.println("Database Version: "+
meta.getDatabaseProductVersion());
}
} // Test
public static void main (String args[]) throws Exception {
test1 test = new test1();
}
}

I'm able to compile but when I run the program, the given error is:

Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager .java:512)
at java.sql.DriverManager.getConnection(DriverManager .java:171)
at test1.<init>(test1.java:10)
at test1.main(test1.java:31)

I have checked that the given IP address is correct, so please can anyone enlighten me about the problem.

Thanks.You must set your database name and port number such as following
Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver:@.255.255.255:1433;Databas eName=MyDB","abc","abc");

You can also use your computer name in url

"jdbc:microsoft:sqlserver://MYSERVER:1433;DatabaseName=MYDB","USERID","PASSWORD"

Originally posted by diablos00
I've download Microsoft SQL Server 2000 JDBC Driver. All these files are being installed and saved in a folder called sql. For example, the IP adress is 255.255.255.255 , I updated the code and saved it as test1.java in this manner:

import java.sql.*;
/**
* Microsoft SQL Server JDBC test program
*/
public class test1 {
public test1() throws Exception {
// Get connection
DriverManager.registerDriver(new
com.microsoft.jdbc.sqlserver.SQLServerDriver());
Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver:@.255.255.255","abc","abc");
if (connection != null) {
System.out.println();
System.out.println("Successfully connected");
System.out.println();
// Meta data
DatabaseMetaData meta = connection.getMetaData();
System.out.println("\nDriver Information");
System.out.println("Driver Name: "
+ meta.getDriverName());
System.out.println("Driver Version: "
+ meta.getDriverVersion());
System.out.println("\nDatabase Information ");
System.out.println("Database Name: "
+ meta.getDatabaseProductName());
System.out.println("Database Version: "+
meta.getDatabaseProductVersion());
}
} // Test
public static void main (String args[]) throws Exception {
test1 test = new test1();
}
}

I'm able to compile but when I run the program, the given error is:

Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager .java:512)
at java.sql.DriverManager.getConnection(DriverManager .java:171)
at test1.<init>(test1.java:10)
at test1.main(test1.java:31)

I have checked that the given IP address is correct, so please can anyone enlighten me about the problem.

Thanks.|||I had the same problem,

The problem is that the Microsoft jdbc driver used unicode and Ianywhere can't handle it.

Use an other jdbc driver from a 3de party will solve this problem.

I used the jdbc driver from datadirect (Type 4 jdbc driver) and this one
was working perfectly. Only thing is you have to pay for it.

I hope i could help you with this.

Greetz|||Microsofts JDBC driver works just fine. In fact it's an old data direct Type 4 driver. Make sure you have the service pack 1 jdbc driver. Here's the exact connection url I use with no problems.

jdbc:jtds:sqlserver://tlmssql3:1388/db1;USER=appsrv1;PASSWORD=password;TDS=8.0

Friday, February 24, 2012

connecting mssql to access and oracle

How do i connect from mssql to access database and oracle
A good example would be fine
I would like to use ODBC or any free tools
THANKS
SEJCreate a linked server or use openquery/openrowset.

Access shold be easy as you should already have the driver but will need to install the oracle connectivity layer for oracle.|||Originally posted by nigelrivett
Create a linked server or use openquery/openrowset.

Access shold be easy as you should already have the driver but will need to install the oracle connectivity layer for oracle.

Can you give some details
I have sql developer 2000 and oracle9i and access on the same machaine with 2000 professional
Novice i am in connectivity issues
with example will help

SJ

Friday, February 17, 2012

Connected to which database

Hello all,

I have a scripts which needs the information about the database in
which it is running.

How can I find out this information.

For example if I want to know the User who has satrted this report, I
use the SYSTEM_USER procedure.

Does an equal procedure exist to find out, on which database the user
is connected to.

Regrads
Franz-JosefYou can the name of the current database with DB_NAME():

SELECT DB_NAME()

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Franz-Josef" <Post@.tophoven.net> wrote in message
news:a0fd39b2.0404280302.403618ee@.posting.google.c om...
> Hello all,
> I have a scripts which needs the information about the database in
> which it is running.
> How can I find out this information.
> For example if I want to know the User who has satrted this report, I
> use the SYSTEM_USER procedure.
> Does an equal procedure exist to find out, on which database the user
> is connected to.
> Regrads
> Franz-Josef

Tuesday, February 14, 2012

Connect via sqldmo

Attempting to connect to MSDE 2000 via sqldmo w/ vb 6 app. For example,
oSqlServer.Connect sSrvName, "sa", sPswd
However, receiving the following error message "Not associated with a
trusted SQL Server connection"
I've looked on microsoft support, which offered a workaround for this error
(kb #889615). However, the workaround applied to Win98. This error is
occuring on a Win xp machine.
any help is appreciated.
hi Jim
jim wrote:
> Attempting to connect to MSDE 2000 via sqldmo w/ vb 6 app. For
> example, oSqlServer.Connect sSrvName, "sa", sPswd
> However, receiving the following error message "Not associated with a
> trusted SQL Server connection"
> I've looked on microsoft support, which offered a workaround for this
> error (kb #889615). However, the workaround applied to Win98. This
> error is occuring on a Win xp machine.
>
usually that exception means MSDE has been installed without allowing
standard SQL Server authenticated connections but trusted connections only
(that is the default)
please have a look at
http://support.microsoft.com/default.aspx?scid=kb;en-us;285097 for futher
info on how to modify the Windows registry to modify the setting..
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://italy.mvps.org
DbaMgr2k ver 0.21.0 - DbaMgr ver 0.65.0 and further SQL Tools
-- remove DMO to reply
|||Hi Andrea,
That absolutely worked! Your help is greatly appreciated. However, it
appears that I have run into another problem when attempting to attach db
files the msde installation.
I'm receiving the following error:
Error -2147216399. Device activation error. The physical file name
'C:\Program' may be incorrect.
I initially that this was due to permission error, so I included
ALLOWXDBCHAINING=1 in the setup parameters, but to no avail. Would it the
actual file location? That is, the space between "Program" and "Files"?
"Andrea Montanari" wrote:

> hi Jim
> jim wrote:
> usually that exception means MSDE has been installed without allowing
> standard SQL Server authenticated connections but trusted connections only
> (that is the default)
> please have a look at
> http://support.microsoft.com/default.aspx?scid=kb;en-us;285097 for futher
> info on how to modify the Windows registry to modify the setting..
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz http://italy.mvps.org
> DbaMgr2k ver 0.21.0 - DbaMgr ver 0.65.0 and further SQL Tools
> -- remove DMO to reply
>
>
|||hi Jim,
jim wrote:
> Hi Andrea,
> That absolutely worked! Your help is greatly appreciated. However, it
> appears that I have run into another problem when attempting to
> attach db files the msde installation.
> I'm receiving the following error:
> Error -2147216399. Device activation error. The physical file name
> 'C:\Program' may be incorrect.
if you are using DMO to perform attabch, backup, restore operations you have
to better enclose paths in square brackets like
fileName = "[c:\program files\folder with spaces\file with spaces.xxx]"
if they include spaces..
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://italy.mvps.org
DbaMgr2k ver 0.21.0 - DbaMgr ver 0.65.0 and further SQL Tools
-- remove DMO to reply
|||Hi Andrea,
Sweet. I will definitely do so. I forgot that the AttachDB() or sp_attach_db
is pretty much a wrapper for CREATE DATABASE.
Thanks again for all of your help.
"Andrea Montanari" wrote:

> hi Jim,
> jim wrote:
> if you are using DMO to perform attabch, backup, restore operations you have
> to better enclose paths in square brackets like
> fileName = "[c:\program files\folder with spaces\file with spaces.xxx]"
> if they include spaces..
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz http://italy.mvps.org
> DbaMgr2k ver 0.21.0 - DbaMgr ver 0.65.0 and further SQL Tools
> -- remove DMO to reply
>
>