写作前言:
有一次我发现,没有服务器的root 和数据库的root,用sqlplus查询的乱码问题实在是太难解决了,所以就采用了java的jdbc 的方法进行查询,但是我发现在linux上面运行java 项目带 jar包的那种真的有点麻烦,所以就研究了一下。
目录:
文章目录
- @[toc]
- 7.加入新包运行出错的解决办法:重新打包 重新生成 配置文件
文章目录
- @[toc]
- 7.加入新包运行出错的解决办法:重新打包 重新生成 配置文件
正文
#在linux上运行Java项目
##1.用inteliji打包
###1.1注意新建一个resource目录,然后把文件放到这里面,据说如果是默认,会出错
###1.2 选择copy 是为了包之间 不杂糅
然后一路默认 最后build artifical
##2.将jar包的根目录上传到linux上,把(里面说明了哪个是main文件,哪个是外来jar) 文件记得拷贝过去,然后运行以下命令
java -jar import_wdgh.jar 这个包中含有main函数
这是拷贝之后的目录结构
##!
7.加入新包运行出错的解决办法:重新打包 重新生成 配置文件
##6.用到的一些运行的命令
java -jar Import_gh.jar
java -jar Import_gh.jar > 将输出信息写到文件总,不换行
##5.代码
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class Operator {
private static String USERNAMR = "ug";
private static String PASSWORD = "ug";
public static String DRVIER = "";
private Formatter f;
private static String URL = "jdbc:oracle:thin:@//url:1521/orcl";
Connection connection;
PreparedStatement pstm;
Statement stmt;
ResultSet rs;
public Operator() {
= new Formatter();
= null;
= null;
= null;
= null;
}
public void AddData(String stuName, int gender, int age, String address) {
= ();
String sql = "select count(*) from student where 1 = 1";
String sqlStr = "insert into student values(?,?,?,?,?)";
int count = 0;
try {
= (sql);
= ();
while(()) {
count = (1) + 1;
((1));
}
= (sqlStr);
(1, count);
(2, stuName);
(3, gender);
(4, age);
(5, address);
();
} catch (SQLException var12) {
();
} finally {
();
}
}
public void AddData_new(String sql) {
= ();
try {
= ();
(sql);
} catch (SQLException var6) {
();
} finally {
();
}
}
public void DeleteData(String stuName) {
= ();
String sqlStr = "delete from student where stu_name=?";
(stuName);
try {
= (sqlStr);
(1, stuName);
();
} catch (SQLException var7) {
();
} finally {
();
}
}
public void DeleteTable(String name) {
= ();
String sqlStr = "DROP TABLE " + name;
try {
= (sqlStr);
();
} catch (SQLException var7) {
();
} finally {
();
}
}
public void UpdateData(String stuName, int gender, int age, String address) {
= ();
String sql = "select id from student where 1 = 1 and stu_name = ?";
String sqlStr = "update student set stu_name=?,gender=?,age=?,address=? where id=?";
int count = 0;
try {
= (sql);
(1, stuName);
= ();
while(()) {
count = (1);
((1));
}
= (sqlStr);
(1, stuName);
(2, gender);
(3, age);
(4, address);
(5, count);
();
} catch (SQLException var12) {
();
} finally {
();
}
}
public void SelectData(String sql) {
String str = "";
= ();
try {
= (sql);
= ();
(str);
("%-10s %20 %10s %10s %10s %10s %10s\n", "单位编号", "单位全称", "单位简称", "上级单位", "单位级别码", "单位级别", "单位类型");
while(()) {
("%-10s", ("bh"));
("%-20s", ("dwmc"));
("%-10s", ("dwjc"));
("%-10s", ("sjdwdm"));
("%-10s", ("dwjbm"));
("%-10s", ("dwjb"));
("%-10s \n", ("dwlx"));
}
} catch (SQLException var7) {
();
} finally {
();
}
}
public void SelectData2() {
= ();
String sql = "select * from employees where 1 = 1";
int count = 0;
try {
= (sql);
for( = (); (); ++count) {
;
}
ResultSetMetaData rsmd = ();
int cols_len = ();
("count=" + count + "\tcols_len=" + cols_len);
} catch (SQLException var8) {
();
} finally {
();
}
}
public Connection getConnection() {
try {
(DRVIER);
= (URL, USERNAMR, PASSWORD);
("成功连接数据库");
} catch (ClassNotFoundException var2) {
throw new RuntimeException("class not find !", var2);
} catch (SQLException var3) {
throw new RuntimeException("get connection error!", var3);
}
return ;
}
public void ReleaseResource() {
if ( != null) {
try {
();
} catch (SQLException var4) {
();
}
}
if ( != null) {
try {
();
} catch (SQLException var3) {
();
}
}
if ( != null) {
try {
();
} catch (SQLException var2) {
();
}
}
}
}