We help IT Professionals succeed at work.

How to access a query using SQLServer 6.5 in a Java Servlet

7of9121098
7of9121098 asked
on
312 Views
Last Modified: 2013-11-24
Can anyone give me a code example using Microsoft's SQLServer 6.5 in a Java Servlet and/or a Java Applet? Especially the Connection string and syntax.
Comment
Watch Question

Hi
  I dont get u what u r asking.But if u want to get the query string methods are available in the HttpServletRequest class.
  So refer JSDK,in HttpServletRequest class u can find out that method.

Author

Commented:
Basically what I want to do is Query a table from Microsoft SQLServer that is in my network. I would like to see an example where a Java Applet and/or Servlet Queries a table from SQLServer.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Cool example CalvinRSmith, Question:
I believe your example assumes that you are running the JSP Server and SQLServer on the same machine. What if the JSP-Server and SQLServer are in different machines. Like for example in ASP to access a SQLServer table and database you use:

CNString="driver={SQLServer};server=MyServer;database=MyDatabaseName;uid=MyUid;pwd=MyPassword"

How would I do this in JDBC: Reference the Name of the Server by IP address or Name, and specifiy the name of the Database etc.

 Help....



Dear 7of9,


    JDBCODBC will not work properly with applets.  If you want to be the database server and web server in different machines you can use IDS server which is available from www.idssoftware.com for evaluation. Modify the code like this.


Class.forName("ids.sql.IDSDriver");
   
      // Connect to the database
      // change MyDB to the name of your odbc name, change sa to the database password, and change the last paramter to the password of the database

 conn = DriverManager.getConnection ("jdbc:ids://databasehost:12/conn?MyDb","sa","");

In this case the web server and database server can be on different machines. IDSDriver is cool. Try
don't forget to add the zip containing
ids.sql package to your classpath which will be there in the IDSinstallation\classes directory.


Try

All the best

       
     
7of9,
   to access sqlserver on a difrent machine create an odbc connection the the servlet machine that uses the sqlserver on a diffrent machine.

Author

Commented:
CalvinRSmith how do I create an odbc connection the the servlet machine that uses the sqlserver on a diffrent machine. Can you please give me a detailed example, I'm new to Java programming. Thanks....
Dear 7of9,

 Try what I have told. It will satisfy your need.IDSDriver is very good.

Bye

Murali
Murali,
   IDSDriver is a good choice for applet development.  If 7of9 is doing servlet development then hitting jdbc:odbc is the best choice.

7of9,
   Creating an odbc connection is not java but rather windows.  here is how to do it:

1) goto start menu -> settings ->   control panal -> odbc data source
2) click the system tab
3) click the add button
4) click on sql server driver
5) click finish
6) enter a name of your choice in the name box
7) enter the name of the sql server in the server box
8) keep hitting next to finish the connection
9) in my code replace MyDB with the name you picked in step 6

Your done!
Dear calvinrsmith ,

       Still you require IIS to use
JdbcOdbc.Because IDSDriver is written entirely in java you can use it anywhere right? If you are using IIS JdbcOdbc is OK. But if you want to be the database server and webserver on different machines,then I think IDSDriver id the best choice. right?
If I am going wrong please correct me.OK

Bye

Murali
Murali,
  No, JdbcOdbc does NOT use IIS.  It simply uses windows odbc to implent the java jdbc driver.  
   What IDSDriver does is to implement jdbc by tunneling all requests through a web server.  This allows applets to use jdbc since the applet is basically telling webpages to hit the database instead of hitting it directly.  Internally IDSDriver still uses ODBC so you will still have to configure the odbc connection as well as a web server for IDSServer to use.  
   Note the following from the faq of IDSServer:

G2. What database does IDS Server support?
All database systems that support ODBC. For example, MS Access, MS SQL Server, Sybase, Oracle, Informix, DB2, dBase, FoxPro, Paradox, BTrieve, etc. In short, if you can find an ODBC driver, IDS Server will work with the corresponding database.
 
G3. Is IDS Server platform independent?
IDS Server is a client/server product. The client side is 100% platform independent. Web applications based the IDS HTML Extensions or the JDBC API can be deployed to and run by any computers with an internet browser. The server side however is currently limited to Intel based Windows NT and Windows 95.
 
____


   As you can see ODBC is used, and only windows is supported as a server.

Calvin

Author

Commented:
Thanks....

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.