尝试使用 JBDC 但错误以非零退出值 1 结束
Trying to use JBDC but getting error finished with non-zero exit value 1
我正在尝试实现 JBDC 的简单使用以用于学习目的,但我收到错误“以非零退出值 1 完成”。下面是我的代码和 gradle.build.
我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionJBDC {
public static void main(String[] args) throws SQLException {
String urlConnection = "jbdc:mysql://localhost/digital_innovation_one";
Connection conn = null;
try {
conn = DriverManager.getConnection(urlConnection , "MyLogin" , "MyPass");
System.out.println("Sucesso");
} catch (Exception e){
System.out.println("Falhou");
} finally {
conn.close();
}
}
}
我的gradle.build:
plugins {
id 'java'
}
group 'one.innovation.digital'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.26'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
我尝试 运行 程序时遇到的错误:
Execution failed for task ':ConnectionJBDC.main()'.
> Process 'command '/usr/lib/jvm/default-java/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
有人可以帮忙吗?我一无所知(这里只是菜鸟)。
首先(根据您的驱动程序版本可能不需要),在开头使用此代码加载您的驱动程序:
try {
Class.forName("com.mysql.jdbc.Driver");
// this class name change according to your driver. In your case, I think it's good one
} catch (ClassNotFoundException e) {
// Cannot find driver for MySQL
}
那你没有设置好的驱动名称。使用这个:
jdbc:mysql://localhost/digital_innovation_one
(jdbc 而不是 jbdc)
我正在尝试实现 JBDC 的简单使用以用于学习目的,但我收到错误“以非零退出值 1 完成”。下面是我的代码和 gradle.build.
我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionJBDC {
public static void main(String[] args) throws SQLException {
String urlConnection = "jbdc:mysql://localhost/digital_innovation_one";
Connection conn = null;
try {
conn = DriverManager.getConnection(urlConnection , "MyLogin" , "MyPass");
System.out.println("Sucesso");
} catch (Exception e){
System.out.println("Falhou");
} finally {
conn.close();
}
}
}
我的gradle.build:
plugins {
id 'java'
}
group 'one.innovation.digital'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.26'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
我尝试 运行 程序时遇到的错误:
Execution failed for task ':ConnectionJBDC.main()'.
> Process 'command '/usr/lib/jvm/default-java/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
有人可以帮忙吗?我一无所知(这里只是菜鸟)。
首先(根据您的驱动程序版本可能不需要),在开头使用此代码加载您的驱动程序:
try {
Class.forName("com.mysql.jdbc.Driver");
// this class name change according to your driver. In your case, I think it's good one
} catch (ClassNotFoundException e) {
// Cannot find driver for MySQL
}
那你没有设置好的驱动名称。使用这个:
jdbc:mysql://localhost/digital_innovation_one
(jdbc 而不是 jbdc)