473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mssql port auto detect

Hi,

In Windows programming, there is a built-in function to get MSSql database server names and connect to it without needing to know the port numbers.

Is it possible to do this in Java (connect to MSSql database without knowing the port number used)?

As far as I know, using JDBC, I would need to know the port numbers to connect to MSSql server. If that's the case, does anybody know if it is possible to detect the port numbers of MSSql?

Regards,
Patrick.
Jun 1 '09 #1
6 3803
JosAH
11,448 Expert 8TB
It depends on your MSSQL driver; see the API documentation for the Driver interface; you can consult it whether or not it accepts a URL without a port number.

kind regards,

Jos
Jun 1 '09 #2
Thanks. I'm sure it needs a port number because I have tried it without a port number, and it won't connect.

My java program uses an ini/text file that stores the port number, to connect to the MSSql database server. User has to input the port number of MSSql into the ini/text file.

However I would like my java program to automatically connect without user needing to know the port number.

I have tried to do this by trial and error, i.e. using a range of port numbers to connect. But, this methods takes too long, 1 second for every port to test.

It would be great if there is a way to connect without needing to know the port number just like in some windows program.
Jun 1 '09 #3
JosAH
11,448 Expert 8TB
Use JNI to consult that built-in function you mentioned; it delivers the valid port numbers to your Java code and you're in business. Or maybe you can write a bit of wrapper code in C/C++ that builds your .ini file for you before your Java process starts.

kind regards,

Jos
Jun 1 '09 #4
Thanks Jos. I'll try to use JNI.
Jun 1 '09 #5
JosAH
11,448 Expert 8TB
@patricktn
Good; basically what you have to do is write a little class with 'native' methods. Feed that class to your 'javah' tool (it comes with your JDK distribution). It generates a .h header file for you than contains the prototypes for all your native methods. User that file (i.e. build another file) that should contain the definitions of all those prototypes. Use your C/C++ compiler to compile it all and build a .dll or .so file out of it.

In your Java code you should use the System.loadLibrary() method to load your .dll (or .so) file and you're up and running ...

kind regards,

Jos
Jun 1 '09 #6
Thanks for the quick reply!

<link removed>
Jun 18 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gordan | last post by:
Hi, I have a site written in PHP with MS SQL Server 2000 as the db backend. When the site was made there was no need for advanced banner rotation so a 10 line script was written and it served...
7
by: mj | last post by:
Hello, thanks for the help. I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm firewall) Apache 2.0.52 MySQL 4.1.7 PHP 5.1.0-dev I have developed a PHP/MySQL web app that...
6
by: sanjana | last post by:
hi i wanna detect if a anything is connected to the usb port I am using system.management class for tht purpose this is my code class usbdetect { public static void Main() { usbdetect we =...
7
by: sanjana | last post by:
hi i wanna detect if a anything is connected to the usb port I am using system.management class for tht purpose this is my code class usbdetect { public static void Main() {
8
by: eugenio | last post by:
Hi...not sure if this is the right group for this posting, but i'm don't know where else to post. I've got a simple problem...I have a linux box running apache 2.0 and php5. I'm trying to use the...
2
by: evle | last post by:
haw to read data from an Infrared Infrared Remote Control
3
by: tc | last post by:
I have an app that I'm re-writing for MySql and MsSql, the old version connected to an Access database. It is more than likely that existing customers will want to upgrade to the later version. I...
0
by: hassanali20 | last post by:
I've surfed this forum and found one thread which was talking about the same problem i've, but it didn't help in my situation. http://www.thescripts.com/forum/thread510563.html I could connect to...
1
by: Andy Bates | last post by:
Hi - Can't see another newsgroup to post this in; so thought I'd post here. I have a C# application that relies on multicast UDP to detect how many PCs the application is executing on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.