gpt4 book ai didi

java - 禁止的包名: java

转载 作者:行者123 更新时间:2023-12-01 23:29:01 27 4
gpt4 key购买 nike

我尝试从名为 jaane 的数据库中获取数据,用户名为 Hello,密码为 hello。错误:

java.lang.SecurityException: Prohibited package name: java
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:480)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: java.Main. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

我的代码是

package java;

import java.awt.Container;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
*
* @author ritesh
*/
public class Main extends JFrame{


public Main() throws SQLException
{super("Database of Students");
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

}
Connection connection = DriverManager.getConnection( "jdbc:derby:/localhost:1527","hello","Hello" );
Statement statement = connection.createStatement();


// query database
ResultSet resultSet =
statement.executeQuery( "SELECT * FROM COLLEAGUES" );
StringBuffer results = new StringBuffer();
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();

for ( int i = 1; i <= numberOfColumns; i++ ) {
results.append( metaData.getColumnName( i ) + "\t" );
}

results.append( "\n" );

while ( resultSet.next() ) {

for ( int i = 1; i <= numberOfColumns; i++ ) {
results.append( resultSet.getObject( i ) + "\t" );
}


}

// close statement and connection
statement.close();
connection.close();

// set up GUI and display window
JTextArea textArea = new JTextArea( "Hello");
Container container = getContentPane();

container.add( new JScrollPane( textArea ) );

setSize( 300, 100 ); // set window size
setVisible( true ); // display window
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
Main window = new Main();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// TODO code application logic here
} catch (SQLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}

}

最佳答案

更改您的包名称。禁止使用 java 作为包名。

编辑:将 Main.java 文件移动到不以 javajavax 开头的(源)目录中 并使用目录结构名称更改代码中的包名称。

关于java - 禁止的包名: java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58297768/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com