-2
我已经在Java中创建了两个应用程序,并且我想将它们连接到同一个数据库中。任何人都可以帮助我的代码示例?Java应用程序连接在同一个数据库中
import java.sql.*;
import javax.swing.*;
public class LidhjaMeSQL {
Connection connection=null;
public static Connection ConnectDB(){
//struktura e kontrollit try-catch
try{
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost/database","root","");
return connection;
}catch(ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
你有两个程序要同时连接到同一个数据库吗?有什么问题? –
是的,我想连接两个应用程序在同一个数据库,但Class.forName(“com.mysql.jdbc.Driver”);给我错误。 –
你会得到什么错误?我需要细节。我们无法猜出发生了什么 –