# Connecting to sql database using sql server 2008



## n_santamaria (Jul 13, 2013)

I've created the connection using ODBC driver but still my program goes into catch block and displays the error message

the program :-;

import java.sql.*;
class ConnectingSQL1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbc:sql1");
System.out.println("Driver Loaded and Connection Created");

Statement stmt = con.createStatement();

stmt.executeUpdate("insert into Students_Record values('Abhishek','32025')");
System.out.println("1 Row Updated");

ResultSet rest = stmt.executeQuery("select * from Students_Record");

String a1="";
String a2="";
while(rest.next())
{
a1=rest.getString(0);
a2=rest.getString(0);
System.out.println("Student name: " + a1 +"Student id: "+ a2);
}
}
catch(Exception e)
{
System.out.println("Error");
}
}
}


----------



## zeeshanaayan07 (Jul 18, 2013)

Coding is working. Thank you


----------

