java写的带数据库的程序如何在没安装数据库的系统上运行

java写的带数据库的程序如何在没安装数据库的系统上运行,第1张

你的问题应该从两个方面进行分析

第一、使用java内嵌式数据库

程序中使用

Derby和HSQLDB等java内嵌式数据库,只需在程序中将数据库配置好即可,是程序专用的。

可以达到你所说的java数据库程序不需要配置在任何机器上运行。

但是,内嵌式数据库的处理能力很低,只适合小数据量的程序使用。

第二、使用Oracle、MSSql、MySql等数据库

首先这些数据库软件需要安装,即使不在本机安装也需要在一台可以访问到的机器上安装,然后使用jdbc访问。

如果程序安装在已经安装这些数据库的机器上,你只需要将程序的数据库访问指向本机即可。

但是,在本机安装数据库的机器很少,大部分都是访问网络上的数据库,这就需要你引入配置文件

在配置文件中进行参数配置。当然,你可以写一些默认配置,当实际环境与默认配置不同时就需要修改默认配置。

所以说不用配置的程序其实是符合你默认配置的程序,你需要根据不同的系统或环境组织自己的默认配置文件。

没有万能的东西,只能是适应大部分,而且需要你在编写程序时提前考虑针对各种运行环境的变化。

有问题请留言吧

其实,也就那几步而已:

别忘了,加载jar文件

加载驱动

获得Connection

获得PreparedStatement /PreparedStatement

执行sql语句

处理结果集ResultSet

关闭连接

mport javasqlConnection;

import javasqlPreparedStatement;

import javasqlResultSet;

import javautilArrayList;

import javautilList;

import EntityJIAJU;

public class JiaJu {

 public JIAJU selectExe(int shouhinId) {

  JIAJU jia = new JIAJU();

  try {

   Connection con = ConnectionManagergetConnection();

   String sql = "select  from jiaju where shouhinId=";

   PreparedStatement ps = conprepareStatement(sql);

   pssetInt(1, shouhinId);

   ResultSet rs = psexecuteQuery();

   if (rs != null) {

    while (rsnext()) {

     jiasetShouhinId(rsgetInt("shouhinId"));

     jiasetShouhinName(rsgetString("shouhinName"));

     jiasetShouhinColor(rsgetString("shouhinColor"));

     jiasetShouhinPrice(rsgetInt("shouhinPrice"));

     jiasetShouhinPai(rsgetString("shouhinPai"));

     jiasetShouhinShi(rsgetString("shouhinShi"));

     // listadd(jia);

    }

   }

  } catch (Exception e) {

   eprintStackTrace();

  }

  return jia;

 }

 public void insertJia(JIAJU jia) {

  try {

   Connection con = ConnectionManagergetConnection();

   String sql = "insert into jiaju values(,,,,)";

   PreparedStatement ps = conprepareStatement(sql);

   pssetString(1, jiagetShouhinName());

   pssetString(2, jiagetShouhinColor());

   pssetInt(3, jiagetShouhinPrice());

   pssetString(4, jiagetShouhinPai());

   pssetString(5, jiagetShouhinShi());

   psexecuteUpdate();

  } catch (Exception e) {

   eprintStackTrace();

  }

 }

 public List selectJia() {

  List list = new ArrayList();

  

  try {

   Connection con = ConnectionManagergetConnection();

   String sql = "select  from jiaju ";

   PreparedStatement ps = conprepareStatement(sql);

   ResultSet rs = psexecuteQuery();

   if (rs != null) {

    while (rsnext()) {

     JIAJU jia = new JIAJU();

     jiasetShouhinId(rsgetInt("shouhinId"));

     jiasetShouhinName(rsgetString("shouhinName"));

     jiasetShouhinColor(rsgetString("shouhinColor"));

     jiasetShouhinPrice(rsgetInt("shouhinPrice"));

     jiasetShouhinPai(rsgetString("shouhinPai"));

     jiasetShouhinShi(rsgetString("shouhinShi"));

        listadd(jia);

    }

   }

  } catch (Exception e) {

   eprintStackTrace();

  }

  return list;

 }

 public JIAJU selectbuy(int shouhinId) {

  JIAJU jia = new JIAJU();

  try {

   Connection con = ConnectionManagergetConnection();

   String sql = "select  from jiaju where shouhinId=";

   PreparedStatement ps = conprepareStatement(sql);

   pssetInt(1, shouhinId);

   ResultSet rs = psexecuteQuery();

   if (rs != null) {

    while (rsnext()) {

     jiasetShouhinId(rsgetInt("shouhinId"));

     jiasetShouhinName(rsgetString("shouhinName"));

     jiasetShouhinColor(rsgetString("shouhinColor"));

     jiasetShouhinPrice(rsgetInt("shouhinPrice"));

     jiasetShouhinPai(rsgetString("shouhinPai"));

     jiasetShouhinShi(rsgetString("shouhinShi"));

    }

   }

  } catch (Exception e) {

   eprintStackTrace();

  }

  return jia;

 }

  public void updateLou(JIAJU jia){

   try{

    Connection con = ConnectionManagergetConnection();

   String sql = "update jiaju set shouhinPrice= where  shouhinId=";

   PreparedStatement ps = conprepareStatement(sql);  

   pssetInt(1,jiagetShouhinPrice());

   pssetInt(2, jiagetShouhinId());

   psexecuteUpdate();

   }catch(Exception e){

    eprintStackTrace();

   }

  }

  public void deleteLou(JIAJU jia){

   try{

    Connection con = ConnectionManagergetConnection();

   String sql = "delete from jiaju where shouhinId=";

   PreparedStatement ps = conprepareStatement(sql);

   pssetInt(1, jiagetShouhinId());

   psexecuteUpdate();

   }catch(Exception e){

    eprintStackTrace();

   }

  }

}

一、新建本地java工程

file->new->java project

二、添加jar包和配置文件

1、添加JAR包

右击Propertie在d出的快捷菜单中选择Java Build Path对话框,在该对话框中单击Libraries选项卡,在该选项卡下单击

Add External JARs按钮,定位到$HBASE/lib目录下,并选取如下JAR包。

hadoop-core-100jar

commons-loggings-versionjar

commons-cli-versionjar

commons-lang-versionjar

commons-configuration-versionjar

hbase-0941jar

zookeeper-343jar

slf4j-api-158jar

slf4j-log4j12-158jar

log4j-1216jar

protobuf-java-241jar

2、添加hbase-sitexml配置文件

在工程根目录下创建conf文件夹,将$HBASE_HOME/conf/目录中的hbase-sitexml文件复制到该文件夹中。通过右键

选择Propertie->Java Build Path->Libraries->Add Class Folder。

3、windows下开发HBase应用程序,HBase部署在linux环境中,在运行调试时可能会出现无法找到主机,类似异常信息如下:javanetUnknownHostException: unknown host: master

解决办法如下:在C:\WINDOWS\system32\drivers\etc\hosts文件中添加如下信息

192168234 master

以上就是关于java写的带数据库的程序如何在没安装数据库的系统上运行全部的内容,包括:java写的带数据库的程序如何在没安装数据库的系统上运行、java 如何连接数据库,如何完成数据库记录添加,删除,修改以及查询。、如何用eclipse中java控制linux中虚拟机中的hbase数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9500782.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存