How can connect sql server 2005 with java in java?

In order to connect MySQL database with Java one need to use below mentioned sample script:

<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>

Class.forName("com.mysql.jdbc.Driver").newInstance ();
java.sql.Connection conn;
conn = DriverManager.getConnection(
"jdbc:mysql:///?user=&password=") ;
Use the JDBC functionality to open a connection to SQL Server.
You can read up on how here:

How to connect MySQL Database from Java

In order to connect MySQL database with Java one need to use below mentioned sample script:

<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>

Class.forName("com.mysql.jdbc.Driver").newInstance ();
java.sql.Connection conn;
conn = DriverManager.getConnection(
"jdbc:mysql:///?user=&password=") ;

Connect to an Oracle database with JDBC in Java

JDBC mean Java Database Connectivity. In java, using JDBC drivers, we can connect to database.
Steps to connect to JDBC.
1) Load the driver, using Class.forName(DriverName);
2) Get the connection object, Connection con = Driver.getConnection(loaded driver name);
3) Create a SQL statement, Statement s = con.createStatement();
4) Create Resultset object using the statement created above, ResultSet rs = s.executeQuery("sql statement");

Iterate the result set to get all the values from the database.

Finally don't miss this
5) s.close();
6) con.close() ;


import java.sql.*;

public class TestDBOracle {

  public static void main(String[] args)
      throws ClassNotFoundException, SQLException
    // or
    // DriverManager.registerDriver
    //        (new oracle.jdbc.driver.OracleDriver());

        String url = "jdbc:oracle:thin:@//server.local:1521/prod";
    //               jdbc:oracle:thin:@//host:port/service
    // or
    // String url = "jdbc:oracle:thin:@server.local:1521:prodsid";
    //               jdbc:oracle:thin:@host:port:SID
    //  SID  - System ID of the Oracle server database instance.
 //         By default, Oracle Database 10g Express Edition
 //         creates one database instance called XE.
 //         ex : String url = "jdbc:oracle:thin:@myhost:1521:xe";

    Connection conn =

    Statement stmt = conn.createStatement();
    ResultSet rset =
         stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while ( {
         System.out.println (rset.getString(1));
    System.out.println ("Ok.");

XML and using Xerces parser for Java to generate and parse XML

his small tutorial introduces you to the basic concepts of XML and using Xerces parser for Java to generate and parse XML.
The intended audience are XML beginners with knowledge of Java.
DOM (Document Object Model ) parser - Tree Structure based API:
    The Dom parser implements the dom api and it creates a DOM tree in memory for a XML document
5.2 SAX (Simple API For XML ) parser - Event Based API
    The SAX parser implements the SAX API and it is event driven interface. As it parses it invokes the callback methods
5.3 When to use DOM parser
  • Manipulate the document
  • Traverse the document back and forth
  • Small XML files
Drawbacks of DOM parser
    Consumes lot of memory 5.4 When to use SAX parser
  • No structural modification
  • Huge XML files
5.5 Validating And Non Validating
DOM and SAX can either be a validating or a non validating parser.
    A validating parser checks the XML file against the rules imposed by DTD or XML Schema.
    A non validating parser doesn't validate the XML file against a DTD or XML Schema.
Both Validating and non validating parser checks for the well formedness of the xml document

View Complete Tutorial here

How to create XML document using java,Java Architecture for XML Binding (JAXB)

In this section, you will  learn to create a XML document using the DOM APIs. This XML document uses  1.0 version  and UTF-8 encoding. 
To work with an XML document it is easy to do so, if you have a document object in place and the XML document loaded in it. Yes, java too has APIs for working with an XML document. With this API, you can navigate through the XML document, or create an XML document from the scratch.
import org.w3c.dom.Document;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder bd = fact.newDocumentBuilder();
doc = bd.newDocument();
Element rt = (Element) doc.createElement("rtElement");
rt.appendChild( doc.createTextNode("Some") );
. . .
. . .
Proper imports are to be done to work with the classes and the methods needed for working with an XML document. The above code sample would give you an idea on how to go about it. Methods like createElement of the Element object are used to create elements.
And these elements are added to the root node using the method appendChild. Lots of sample codes are available in the internet on this topic.
 Here is Java File:

How to Create Running Total Field in Crystal Reports


A running total field in a Crystal report is a summary field that allows you to control how and when the summary is calculated, and when it is reset.
In this tutorial, you will create a running total field and insert it into a report.

View Complete Tutorial here

VB.NET Crystal Reports Summary Fields

The following C# - Crystal Reports section describes how to add a summary field in the Crystal Reports
In the Crystal Reports designer view window, right click on the Report Footer , just below the Total field and select Insert -> Summary .

Then you will get a screen , select the Total from the combo box and select Sum from next Combo Box , and summary location Grand Total (Report Footer) . Click Ok button

Now you can see @Total is just below the Total field in the report Footer

Now the designing part is over and the next step is to call the Crystal Reports in C# and view it in Crystal Reports Viewer control .

Select the default form (Form1.cs) you created in C# and drag a button and a CrystalReportViewer control to your form .

You have to include CrystalDecisions.CrystalReports.Engine in your C# Source Code.

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

How to create a login page in Aspnet with sqlserver

First we have to create a database for storing the login information

Open the Sqlserver Management studio

Create a new database and change the database name as db_Logininformation

Create a New table in that database(db_Logininformation) and change the table name as tab_userinformation
Now, create the following fields

  1. UserID   int         PrimaryKey  
  2. username varchar(50)  
  3. Password varchar(50)  
Next, Enter the some usernames and paasword directlu in the database for checking purpose

and save the table

Next ,open the Microsoft visual studio 2008

Next,select the Aspnet web application and change the name as LoginPage

Next,come to the design page of LoginPage and drag and drop two labels,two textboxes and button

next,come to the code page of the Login.aspx.cs

Write the following codein the page event
  1. protected void Button1_Click(object sender, EventArgs e)  
  2.     {        
  3.         con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ToString());  
  4.         con.Open();  
  5.         com = new SqlCommand("select Password from userinformation where Username='" + txt_uname.Text + "'", con);  
  6.         dr = com.ExecuteReader();  
  7.         if (!dr.Read())  
  8.         {  
  9.             Response.write("Invalid User");  
  10.         }  
  11.         else  
  12.         {  
  13.             if (dr[0].ToString() == txt_pwd.Text)  
  14.             {  
  15.                 Response.Redirect("~/mainPage.aspx");  
  16.             }  
  17.             else  
  18.             {  
  19.                Response.write("Wrong Password");  
  20.                txt_pwd.Focus();  
  21.             }  
  22.         }  
  24.     } 

How to Create ASP.NET Session Login Without Cookies

The following describes the easiest way I have found to force users to log into an ASP.NET website for each session but not require them to accept cookies. You must do the following things.
  1. Create a Web.config file with the appropriate entries to allow session state management.
  2. Create a well formed Global.asax file with the code below included in it.
  3. Create a login page to authenticate users against a database or whatever method you desire.
' Fires when the session is started and sets the default loggedin state to ""

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("Loggedin") = ""
End Sub
' Called when the request has been process by the Request Handler and 

' HttpSessionState is available [This is the key piece of code that forces 

' the user is login check with each page request]

Sub Application_OnPostRequestHandlerExecute()
End Sub
'Check that the user is logged in.

Sub CheckLoggedIn()
'If the user is not logged in and you are not currently on the Login Page.

If Session("LoggedIn") = "" And InStr(Request.RawUrl, "Login.aspx") = 0 Then
End If
End Sub
Finally create a Login.aspx file that authenticates the user. If the user is allowed in, set: Session("Loggedin") = "Yes"
That's all there is to it. Hope this helps! Enjoy!

Create Login Page with ASP Connected to Database

dim username, password, loginButton
if logButton then
   Dim Con, sql, rec
   set Con = Server.CreateObject("ADODB.Connection")
   Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")
   'Select the record matching the username.
   sql = "SELECT * FROM tblusers WHERE UCase(username)='
"& UCase(username) & "' AND UCase(password)=' " & UCase(password) & " ' "
   set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
      blankError="Invalid username." 'EOF is true, no match found.
   end if
end if
<form name="productForm" method="post" action="<%=Request.ServerVariables("URL")%>">
<table border =1>
<tr><td colspan="2">

if blankError<>"" then
Response.Write("<center><font color='red' size='3'>"&blankError&"</font></center>")
end if
<td><Strong><font face="courier new" size="3">Username:</font></strong></td>
<td><input type="text" name="username" size="35"></td>
<td><Strong><font face="courier new" size="3">Password</font></strong></td>
<td><input type="password" name="password" size="35"></td>
<tr><td colspan="2" align="center"><input type="submit" name="loginButton" value="Login">
<input type="reset" name="reset" value="Clear"></td>