我是Java的新手,我需要建立一个连接到MySQL服务器(本地),我已经在Intellij中添加了库,但它似乎不起作用,IDE无法找到我认为的类......我变得疯狂我正在寻找两个小时......我来自visual studio/c#dev环境,我想我应该错过一些东西......
在这里,您可以从我的IDE和我想要使用的简单代码中获取图片.您还可以推断我已经在我的项目中导入了jar(mysql-jdbc).
编辑:这是代码,注释显示错误出现的位置:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import org.*;
import com.mysql.jdbc.Driver;
public class JdbcLogin {
public String Login;
public String MotDePasse;
private boolean Logged = false;
public void StartBdd(){
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName); // here is the ClassNotFoundException
String serverName = "localhost";
String mydatabase = "suptodo";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
String username = "root";
String password = "azerty";
Connection connection = DriverManager.getConnection(url, username, password);
}
}
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个WPF应用程序,它首先在LocalDb上使用实体框架/代码(我已经在"模型"目录上创建了我的数据库,一切似乎都很好).
它在我的笔记本电脑上工作得很好,我想与我的朋友分享,但它不起作用.我想我在另一台计算机上有一个SQL错误,但它没有显示它.它只是显示一个Windows应用程序错误...我认为这是我尝试加载我的数据库上下文.
我的数据库环境:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
namespace ModernUINavigationApp1.Model
{
class Supcontext : DbContext
{
public DbSet<InfosConnexion> InfosConnexions { get; set; }
public DbSet<InfosFichiers> InfosFiles { get; set; }
public DbSet<Log> Logs { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我的app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" …Run Code Online (Sandbox Code Playgroud)