myeclipse打包java项目,mysql数据库怎么打包进去?
怎么把数据库打包进去,我用fatjar打包之后,数据库的驱动包是打包进去了的,然后我生成了exe。在我自己的电脑上可以运行,没有问题,可是传给另一台电脑之后,就无法连接数据库了,数据无法显示。具体的log是这样的:JarClassLoader: Warning: Unable to load native library: java.lang.NullPointerException
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at frame.NewSWTApp.button1MouseDown(NewSWTApp.java:329)
at frame.NewSWTApp.access$4(NewSWTApp.java:325)
at frame.NewSWTApp$5.mouseDown(NewSWTApp.java:283)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at frame.NewSWTApp.main(NewSWTApp.java:320)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.simontuffs.onejar.Boot.run(Boot.java:306)
at com.simontuffs.onejar.Boot.main(Boot.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
……
追问:127.0.0.1?不能联网岂不是无法访问数据库了?怎样才能不联网也能访问数据库呢?不是很多应用程序都不必联网都能使用数据库么?/加载JDBC驱动
Class.forName("com.mysql.jdbc.Driver");
//连接到数据库
String dbUrl="jdbc:mysql://localhost:3306/mypetshop";
Connection c=DriverManager.getConnection(dbUrl,"root","fly");
代码是这样不对的吗?改成我的ip还是不行。/加载JDBC驱动
Class.forName("com.mysql.jdbc.Driver");
//连接到数据库
String dbUrl="jdbc:mysql://localhost:3306/mypetshop";
Connection c=DriverManager.getConnection(dbUrl,"root","fly");
这是链接数据库的代码。
答案:当然不对了,把localhost改成你的数据库主机的ip地址
其他:'root'@'localhost' ?
改成你数据库所在的计算机的地址,不然的话,别人还要装一个数据库,然后建库建表才行 有问题到疯狂java论坛,那有疯狂java系列丛书的作者李刚,会帮你解答java上的问题,可以浏览李刚创建的疯狂软件教育中心网站。 把你的获得connection的方法的 localhost改成 你电脑的ip 或者是 数据库所在电脑的ip localhost 指定的是本机 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at frame.NewSWTApp.button1MouseDown(NewSWTApp.java:329)
at frame.NewSWTApp.access$4(NewSWTApp.java:325)
at frame.NewSWTApp$5.mouseDown(NewSWTApp.java:283)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at frame.NewSWTApp.main(NewSWTApp.java:320)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
上一个:知道一个字段名,怎样查到它在数据库里的哪张表里,mysql
下一个:mysql中数据怎么一次插入到多张表中的相同字段中