• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Connecting to sql database using sql server 2008

n_santamaria

Right off the assembly line
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("jdbc:eek:dbc: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");
}
}
}
 
Top Bottom