扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
java程序需要设置proxy才能生效:
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的辛集网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
String url="";
Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1", 8888));
URL serverUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(proxy);
package com.daidai.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
Configuration conf=new Configuration().configure();
sessionFactory=conf.buildSessionFactory();
return sessionFactory;
}
public static void setSessionFactory(SessionFactory sessionFactory) {
HibernateUtil.sessionFactory = sessionFactory;
}
public static Session getSession(){
return sessionFactory.openSession();
}
}
package com.daidai.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class Util {
private static String Cellphone_Number;
private static String Cellphone_Number1;
private static String Cellphone_Number2;
private static String Fasten_Telephone;
private static String Fasten_Telephone2;
private static String name;
private static String remarks;
public static Sheet rs;
public Util(){}
static{
try{
Workbook rwb=Workbook.getWorkbook(new File("Book1.xls"));
rs=rwb.getSheet(0);
int count=rs.getColumns();
System.out.println(count);
int count1=rs.getRows();
System.out.println(count1);
//获取第一行,第一列的值
//count1行
//count列
for(int i=0;icount1;i++){
for(int j=0;jcount;j++){
Cell c00 = rs.getCell(j, i);
String strc00 = c00.getContents();
//获取第一行,第二列的值
Cell c10 = rs.getCell(1, 0);
String strc10 = c10.getContents();
System.out.println(strc00);
System.out.println(strc10);
}
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[]args){
Util u=new Util();
}
}
?xml version='1.0' encoding='utf-8'?
!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
""
hibernate-configuration
session-factory
property name="connection.driver_class"
com.mysql.jdbc.Driver/property
property name="connection.url"
jdbc:mysql://127.0.0.1:3306/test/property
property name="connection.username"
root/property
property name="connection.password"
daidai/property
!-- SQL dialect 数据库方言--
property name="dialect"
org.hibernate.dialect.MySQLDialect/property
!-- Echo all executed SQL to stdout --
property name="show_sql"true/property
property name="hbm2ddl.auto"create/property
mapping resource="User.hbm.xml"/
/session-factory
/hibernate-configuration
?xml version="1.0" encoding="utf-8"?
!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
""
hibernate-mapping package="com.daidai.entity"
class name="User" table="t_user"
id name="id"
generator class="native"/
/id
property name="name" type="java.lang.String" length="15"/
property name="Cellphone_Number" type="java.lang.String" length="11"/
property name="Cellphone_Number1" type="java.lang.String" length="11"/
property name="Cellphone_Number2" type="java.lang.String" length="11"/
property name="Fasten_Telephone" type="java.lang.String" length="11"/
property name="Fasten_Telephone2" type="java.lang.String" length="11"/
property name="remarks" type="java.lang.String"/
/class
/hibernate-mapping
package com.daidai.dao.impl;
import com.daidai.util.*;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.daidai.dao.UserDAO;
import com.daidai.entity.User;
public class UserDAOImpl implements UserDAO {
public Session session=null;
public void save(User user) {
try {
session=HibernateUtil.getSession();
session.getTransaction().begin();
session.save(user);
session.getTransaction().commit();
} catch (HibernateException e) {
session.getTransaction().rollback();
e.printStackTrace();
throw e;
}
}
}
package com.daidai.dao;
import com.daidai.entity.User;
public interface UserDAO {
public void save(User user);
}
1.确保写的类没问题,java程序是先编译,后执行
2.打开cmd,进入该文件所在路径,输入javac -d 类名.java,对该java源文件编译,生成class文件
3.再输入java 类名 ,就可以运行这个程序了。
如果有多个类,需要写个bat批处理文件,即同时运行多个java类、jar包、配置文件、资源文件。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流