473,378 Members | 1,377 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,378 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 3802
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.