我尝试在NetBeans(8.1)上从ACCESS2016获取数据我打开控制面板并选择管理工具和数据源(ODBC)然后我选择了我的驱动程序并将数据库与项目连接起来这是什么问题?
提示: 我还在数据库的开头,这是我第一个使用数据库的项目
控制台窗口
java.lang.SecurityException: Prohibited package name: java.database.project
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:659)
at java.lang.ClassLoader.defineClass(ClassLoader.java:758)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
我的代码
package java.database.project;
import java.sql.*;
public class JavaDatabaseProject {
Connection con ;
Statement st ;
ResultSet rs ;
public void connect()
{
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String JavaDatabaseProject = "jdbc:odbc:DB1";
con = DriverManager.getConnection(JavaDatabaseProject);
st = con.createStatement();
String sql = "select * from Tablel";
rs = st.executeQuery(sql);
while(rs.next())
{
String fname = rs.getString("Fname");
String lname = rs.getString("Lname");
String age = rs.getString("Age");
System.out.println(fname + " " + lname + " " + age);
}
}catch(Exception ex)
{
}
}
public JavaDatabaseProject()
{
connect();
}
public static void main(String[] args)
{
new JavaDatabaseProject();
}
}