蔡鸟期待您的答复,一个关于java和mysql 的问题????????????

hai3qing 2005-04-12 02:18:56
我写了一个连接mysql数据库的程序:
/*
* Created on 2005-4-10
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.by.cngp;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;;
/**
* @author bin
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class test {
public static void main(String[] args){
String tablename;
Connection sqlConn=null;
PreparedStatement stmt=null;
LogApp logapp = new LogApp();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
sqlConn = DriverManager.getConnection(
"jdbc:mysql://localhost/phs?&useUnicode=true&characterEncoding=GBK","usr","!!^");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMddHHmmsss");
java.util.Date rightNow = new java.util.Date();
String now = sdf.format(rightNow);
System.out.println(now);
tablename="tbrcvlog"+Integer.toString(rightNow.getMonth()+1);

stmt = sqlConn.prepareStatement("insert into tbrcv(msgid,isreport,msgformat,recvtime,srctermid,desttermid,msglength,msgcontent,ProtocolID_Parameter,Protocol_Length,Protocol_value,flag) values(?,?,?,?,?,?,?,?,?,?,?,?)");
stmt.setString(1,"0123456798");
stmt.setString(2,"1");
stmt.setString(3,"15");
stmt.setString(4,now);
stmt.setString(5,"106010180001023");
stmt.setString(6,"97171");
stmt.setInt(7,234);
stmt.setString(8,new String("你好啊噢测试哦".getBytes("GB2312"),"ISO8859-1"));
stmt.setDouble(9,2);
stmt.setDouble(10,3);
stmt.setInt(11,4);
stmt.setString(12,"N");

stmt.executeUpdate();
stmt = sqlConn.prepareStatement("insert into tbrcvlog(msgid,isreport,msgformat,recvtime,srctermid,desttermid,msglength,msgcontent,ProtocolID_Parameter,Protocol_Length,Protocol_value,flag) values(?,?,?,?,?,?,?,?,?,?,?,?)");
stmt.setString(1,"0123456798");
stmt.setString(2,"1");
stmt.setString(3,"15");
stmt.setString(4,now);
stmt.setString(5,"106010180001023");
stmt.setString(6,"97171");
stmt.setInt(7,234);
stmt.setString(8,new String("你好啊噢测试哦".getBytes("GB2312"),"ISO8859-1"));
stmt.setDouble(9,2.0);
stmt.setDouble(10,3);
stmt.setInt(11,4);
stmt.setString(12,"N");
stmt.executeUpdate();
}catch(SQLException e){
//display SQL specific exception information
logapp.log("********************");
logapp.log("SQLException in mainL"+e.getMessage());
logapp.log("**SQLState:"+e.getSQLState());
logapp.log("**SQL Error Code:"+e.getErrorCode());
logapp.log("********************");
e.printStackTrace();
}catch(Exception e){
LogApp.log("Exception in main:"+e.getMessage());
e.printStackTrace();
}finally{
try{
if(sqlConn!=null)
sqlConn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}

这个程序在我本机上执行是没有问题的,我本机上装的是jdk1.4,但我把这个程序传到服务器上执行,就出这个错误:
bash-2.04$ sh java_test.sh
java_test.sh: !#/bin/sh: No such file or directory
Note: com/by/cngp/test.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at com.by.cngp.test.main(test.java:27)
说我没有那个文件,这个文件在jdk1.4里有,1.3里没有。如果我用这个命令:
java -classpath .:../lib/log4j-1.2.8.jar:../lib/mysqldriver.jar:../lib/lib_1.4.2_03/rt.jar: com/by/cngp/test
则服务器出现这个错误:
bash-2.04$ java -classpath .:../lib/log4j-1.2.8.jar:../lib/mysqldriver.jar:../lib/lib_1.4.2_03/rt.jar: com/by/cngp/test
java.sql.SQLException: Cannot load connection class because of underlying exception: 'java.lang.SecurityException: Prohibited package name: java.sql'.
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:277)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at com.by.cngp.test.main(test.java:27)
现在服务器的环境不能改,要保持jdk1.3,而我又想让我的程序运行,我应该怎么办呢?请教高手!!! :idea: :idea: :idea:
...全文
101 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
booleyu 2005-04-12
服务器有什么不能该的?不就是换个jdk嘛!
回复
bestdelphier 2005-04-12
你用jdk1.4开发的程序用到了1.3不支持的方法。

jdk是向下兼容的,但不能向上兼容。
回复
hai3qing 2005-04-12
也要用jdk1.3才行吗?
回复
bestdelphier 2005-04-12
把你开发用机的jdk改成和服务器一致然后重新开发!开发人员不应该犯这种错误的。
回复
相关推荐
发帖
Java SE
创建于2007-09-28

6.2w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2005-04-12 02:18
社区公告
暂无公告