Search code examples
javamssql-jdbc

java jdbc and odbc bridge how to stablish in linux


this is my code in Java and i am using Linux mint i have installed mysql in mu Linux OS and then i try to run that program, program run accurate but database did not change i do not know why ..

import java.sql.*;
import java.io.*;
public class InsertTest
{
public static void main(String[] args)
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the id");
int id=Integer.parseInt(br.readLine());
System.out.println("enter the name");
String name=br.readLine();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:testdb");
PreparedStatement stmt= con.prepareStatement("insert into student values(?,?)");
stmt.setInt(1,id);
stmt.setString(2,name);
stmt.executeUpdate();
System.out.println("record is inserted");
con.close();
}catch(Exception e)
{
System.out.println(e);
}
}
}

output of the program is --|

enter the id
110
enter the name
joshi
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

Solution

  • You need to download the ojdbc7.jar (or similar depending on your jdk version) and add it to your project. Look up info on how to do that depending on your IDE