java代码小段

1. 我有个岗位菜单对应表USER_GW_MENU,有两个字段(gw_id岗位代码,menu_id菜单代码)一个岗位可以有很拥有很多菜单.当我写一个javabean的时候,定义了一个函数,public void add_gw_menu(String  gw_id,String  menu_id[]),这个函数是用来设置岗位菜单的.
请问我应该如何写这段代码,调用这个add_gw_menu(String,String)方法后,把它读进数据库.

Connection c=null; 

PreparedStatement pstmt = null ;
try
{
   c=ConnectionHelper.getConnection();
   for(int i=0;i <s_menu_id.length;i++)
   { 
       String sql="insert into USER_GW_MENU(GW_DM,MENU_ID) values (?,?)";
       c.setAutoCommit(false);
       pstmt=c.prepareStatement(sql);
       pstmt.setString(1, s_gw_dm);
       pstmt.setString(2, s_menu_id[i]);
       if (pstmt.executeUpdate() == 0) {
          throw new ConcurrencyException("不能正常设置!");
       }
       c.commit();

   }
}

 

2. 读取文件内容

import java.io.*;

/**
 * 读取文件内容
 * @author 张斌
 */
public class ReadFile {
 
 public void readFile(String pathname) throws IOException {
  File file = new File(pathname);
  BufferedReader br = new BufferedReader(new FileReader(file));
  String context;
  while ((context = br.readLine()) != null) {
   System.out.println(context);
  }
  br.close();
 }

 public static void main(String[] args) {
  ReadFile rf = new ReadFile();
  try {
   rf.readFile("F://desk.ini");
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
 
}

 

3. 指定文件内容的替换,输出到新文件

import java.io.*;

/**
* 指定文件内容的替换,输出到新文件
*
@author 张斌(小神)
*
*/
public class ReplaceString_File {
   
   
/**
     *
     *
@param pathName : 读取文件路径
     *
@param newPathName : 输出文件路径
     *
@param course : 要修改的字串
     *
@param value : 新字串
     *
@throws IOException
    
*/
   
public void replaceString(String pathName, String newPathName, String course, String value) throws IOException {
        File file
= new File(pathName);
        File file_output
= new File(newPathName);
       
if (file.exists()) {
            BufferedReader br
= new BufferedReader(new FileReader(file));
            BufferedWriter bw
= new BufferedWriter(new FileWriter(newPathName));
            String context;
           
while ((context = br.readLine()) != null) {
                context.replace(course, value);
                bw.write(context);
                bw.newLine();
               
//System.out.println(context);
            }
            bw.flush();
            br.close();
            bw.close();
        }
    }
   
   
public static void main(String[] args) {
        ReplaceString_File rsf
= new ReplaceString_File();
       
       
try {
            rsf.replaceString(
"F://321.txt", "F://123.txt", "def=456", "def=654");
        }
catch (IOException e) {
            e.printStackTrace();
        }
    }

}
 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值