Sie sind auf Seite 1von 4

How to create a database in SQL server ?

Open SQL Server

Click on database icon .

Right Click popmenu will appear choose new database.

A window will appear here give the name of your database (eg.Student_db) and click OK.

Then you will find the student_db will be added under database directory.

Select Student_db then double click .

You will find more directory are there , select table and right click and choose NEW Table

Now here enter two fields user_name varchar(20) and password varchar(20)

Save the table as login .

How to create DSN in SQLServer ?

Go to Start → control panel →Administrative tools → ODBC→ click on System DSN→

Click on ADD → create new DSN window will Appear on that window Select SQL Server

→Click Finish

A new window will prompt

Enter the name of the DSN (eg Student_dsn)

Leave the description box empty

Go to next box enter the name of your SQL Server Connection like(eg. AF2\SQLEXPRESS)

Note: start your Sql server . copy the server Name and paste (this name is required)

When you fill all the information there click on next button.

Now your in different tab

You will find Message like “ How should SQL Server verify the authenticity of the login ID? “

Choose window NT authentication using Network login ID

Then click on next


In this window choose the default database that you have created in SQL Server from the Combo box.

And leave everything as it is. Then click on Next. Then next window will appear click on finish.

When you click on finish button a new window will appear there u will find button with the name TEST data Source click that
button will find the message “test completed successfully”( if you enter the all field correctly). Click ok

Then again Ok and come out by pressing OK button.


How to insert data from net beans to SQL server ?

Create a new project in net beans with the name login .

Then double click on project .

You will find source package, Test package….etc directory

Double click on source package you will find login directory ,select login and right click a new box will appear choose new frame
and insert the the item according to picture shown below.
Then right click on insert button and click event choose action performed

Inside that area type following code :

String user = jTextField1.getText();

String pwd = jTextField2.getText();

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:manish");

//String qry = "";

PreparedStatement stmt = con.prepareStatement("insert into login values(?,?)");

stmt.setString(1,user.toString());

stmt.setString(2,pwd.toString());

stmt.executeQuery();

con.close();

}catch(SQLException e){

e.printStackTrace();

}catch(ClassNotFoundException e){

Then go to build and select clean and build main project .

There after run the program.

Das könnte Ihnen auch gefallen