это мой код на Java, и я использую Linux Mint. Я установил mysql в свою ОС Linux, а затем пытаюсь запустить эту программу, программа работает точно, но база данных не изменилась, я не знаю, почему ..
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);
}
}
}
вывод программы --|
enter the id
110
enter the name
joshi
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
пытается загрузить классsun.jdbc.odbc.JdbcOdbcDriver
, если он указан в вашем пути к классам. Если нет, будет выброшеноjava.lang.ClassNotFoundException
. Добавьте соответствующий JAR-файл драйвера в путь к классам. - person Alexander   schedule 06.05.2018