Help .. am new to db in hava

hi there
i have this code i guess its a database connection to MYSQL ...
i need to change it to SQL SERVER 2000 .....
so how it differs .....?????and i need some comments to understand what its all about ?
please this is urgent ....???
* Servlet for DB connection*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class getConnection extends HttpServlet
public void init()
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
BufferedReader in = request.getReader();
String db = in.readLine();
String user = in.readLine();
String pwd = in.readLine();
/*String db = "test";
String user = "root";
String pwd = "caspian";*/
String message ="jdbc:mysql://localhost:3306/"+
db+","+user+","+pwd;
try
connect(db.toLowerCase().trim(),user.toLowerCase().trim(),
pwd.toLowerCase().trim());
message += "100 ok";
catch (Throwable t)
message += "200 " + t.toString();
response.setContentType("text/plain");
response.setContentLength(message.length());
PrintWriter out = response.getWriter();
out.println(message);
out.println(db);
out.println(user);
out.println(pwd);
out.flush();
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
doPost(request,response);
/* This method connects to MYSQL database*/
private void connect(String db, String user,
String pwd) throws Exception
// Establish a JDBC connection
// to the MYSQL database server.
//Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/"+db,user,pwd);
// Establish a JDBC connection to the Oracle database server.
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
//Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:"+db,user,pwd);
// Establish a JDBC connection to the SQL database server.
//Class.forName("net.sourceforge.jtds.jdbc.Driver");
//Connection conn = DriverManager.getConnection(
// jdbc:jtds:sqlserver://localhost:1433/+db,user,pwd);
}

I've added comments and fixed the formatting (and use the [ code ] tags to make it more readable).
However, you can figure 90% of this out from reading the java.sql API:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/package-summary.html
and the rest you can get by Googling for tutorials and documentation, such as this one:
http://support.microsoft.com/default.aspx?scid=kb;en-us;313100
You might also look at the basics of httpservlet, e.g.:
http://www.jayeckles.com/tutorials/servlets.pc
/* Servlet for DB connection*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class getConnection extends HttpServlet
  // HttpServlet - init() method should only present if it's being overridden
  //public void init()
  public void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException
    // this isn't how you normally get request information from an http request
    // BufferedReader in = request.getReader();
    // get the parameters from the web form by name
    // replace the quoted values with whatever the fields actual names are
    //    and clean up the data ASAP
    String db = request.getParameter("db").toLowerCase().trim();
    String user = request.getParameter("user").toLowerCase().trim();
    String pwd = request.getParameter("pwd").toLowerCase().trim();
    /*String db = "test";
    String user = "root";
    String pwd = "caspian";*/
    String message ="jdbc:mysql://localhost:3306/"+db+","+user+","+pwd;
    try
      connect(db,user,pwd);
      message += "100 ok";
    // you normally shouldn't catch Error throwables, only the Exception throwables
    //   Error throwables are non-recoverable errors and it's usually a bad thing to catch them
    catch (Exception e)
      message += "200 " + e.toString();
    response.setContentType("text/plain");
    // it's not required to set a ContentLength, but it you do set it, DO NOT set it wrong
    //    if set, it should be the length of everything set to the "out" PrintWriter,
    //      including line end characters
    // response.setContentLength(message.length());
    PrintWriter out = response.getWriter();
    out.println(message);
    out.println(db);
    out.println(user);
    out.println(pwd);
    // this is unneeded, flush is automatic when the servlet ends
    //    it can't hurt and in some scenarios it's helpful
    // out.flush();
  // treate GET requests the same as posts
  public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException
    doPost(request,response);
  /* This method connects to MYSQL database*/ 
  private void connect(String db, String user, String pwd) throws Exception
    // Establish a JDBC connection
    // to the MYSQL database server.
    //Class.forName("org.gjt.mm.mysql.Driver");
    // load the MySQL driver class
    // every database has a different one
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    // ask the driver manager for a connection for this database URL
    // this assumes that the database is running on your machine and
    //     is using the standard MySQL port
    // the DriverManager figures out which driver is needed by asking each loaded driver
    //    if it knows how to handle the database URL, the first paramter of the method
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db,user,pwd);
    // Establish a JDBC connection to the Oracle database server.
    //DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    //Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:"+db,user,pwd);
    // Establish a JDBC connection to the SQL database server using the jtds driver.
    //Class.forName("net.sourceforge.jtds.jdbc.Driver");
    //Connection conn = DriverManager.getConnection(
    // jdbc:jtds:sqlserver://localhost:1433/+db,user,pwd);
}

Similar Messages

Maybe you are looking for

  • How do you download Kindle book to iPhone 5s?

    I have many Kindle books I've purchased from Amazon; they are accessible to me on-line and I can download them at will to my Kindle.  But how can I download them to my Iphone 5s?

  • 'Undo' no longer working in Outlook inbox after a message delete

    I've been using Outlook 2010 for a couple of years; I used to occasionally use 'Undo' (or ctrl-Z) to bring back a message I had just deleted from Inbox after reading it. It was a limited undo - I could only bring back the one message - but it did get

  • Need faqs on ABAP HR basics

    Hi folks,           I need faqs on ABAP HR (with answers).  Could any body send me some material to attend interview on ABAP HR.Please i want with ansers as i amvery new to ABAP HR.             Thanks,            Shyam.

  • What kind of timeouts present in SAP Portal?

    Hi there, i have a Question. In the portal there are Session Timeouts. Thats OK. But now i want to know what kind of other timeouts are in the portal. Can you help here? Thanks Bjoern

  • Error during installing Asphalt Elite racing

    Iam using nokia N86 8MP. I have downloaded and installed Asphalt Elite racing game. I accidentally uninstalled it. When Iam trying to download and install it again, it is showing that the application could not be completed due to an error. Can anyone