所有功能都在工作,只有添加才是问题
java trowing异常:
public class Maintest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DBConnector dbConn = DBConnector.getInstance();
ArrayList<Project> projects = dbConn.qSelect(null);
for(int i=0; i<projects.size(); i++){
System.out.println(projects.get(i).getId());
}
Project newProject = new Project();
double kkk=3;
newProject.setId(new Integer(10011));
newProject.setName("newName");
newProject.setOt_collection_id("newOtCollectionId");
newProject.setDoi("newDoi");
newProject.setAka("newAka");
newProject.setCollection_platform("newCollectionPlatform");
newProject.setDataset_overwiew("newDatasetOverwiew");
newProject.setDataset_acknowledgement("newDatasetAcknowledgement");
newProject.setKeywords("newKeywords");
newProject.setFunder("newFunder");
newProject.setCollector("newCollector");
newProject.setArea(kkk);
newProject.setPoint_density(kkk);
newProject.setX_coordinate(kkk);
newProject.setY_coordinate(kkk);
newProject.setCoordinates_system("newCoordinatesSystem");
newProject.setLink_truview("newLinkTruView");
newProject.setSurvey_date("newSurveyDate");
newProject.setTotal_lidar_returns("newTotalLidarReturns");
newProject.setImage("none.jpg");
dbConn.addProject(newProject);
}
下面是dbconnector类:
public class DBConnector {
private Connection c = null;
private Statement stmt = null;
private static DBConnector me = null;
public static DBConnector getInstance() {
if (me == null)
me = new DBConnector();
return me;
}
private DBConnector() {
c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/postgres", "postgres",
"pass");
c.setAutoCommit(false);
stmt = c.createStatement();
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
public void deleteProject(Integer id) {
String sql = "DELETE from DIPLOMSKI_PROJEKTI where ID=" + id.toString()
+ ";";
try {
stmt.executeUpdate(sql);
c.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void addProject(Project proj) {
String sql = "INSERT INTO DIPLOMSKI_PROJEKTI (ID,NAME,OT_COLLECTION_ID,DOI,AKA,COLLECTION_PLATFORM,DATASET_OVERWIEW,DATASET_ACKNOWLEDGEMENT,KEYWORDS,FUNDER,COLLECTOR,AREA(KM2),POINT_DENSITY(PTS_PER_M2),X_COORDINATE,Y_COORDINATE,COORDINATES_SYSTEM,LINK_TRUVIEW,IMAGE,SURVEY_DATE,TOTAL_LIDAR_RETURNS(PTS)) "
+ "VALUES ("
+ proj.getId()
+ ",'"
+ proj.getName()
+ "','"
+ proj.getOt_collection_id()
+ "','"
+ proj.getDoi()
+ "','"
+ proj.getAka()
+ "','"
+ proj.getCollection_platform()
+ "','"
+ proj.getDataset_overwiew()
+ "','"
+ proj.getDataset_acknowledgement()
+ "','"
+ proj.getKeywords()
+ "','"
+ proj.getFunder()
+ "','"
+ proj.getCollector()
+ "',"
+ proj.getArea()
+ ","
+ proj.getPoint_density()
+ ","
+ proj.getX_coordinate()
+ ","
+ proj.getY_coordinate()
+ ",'"
+ proj.getCoordinates_system()
+ "','"
+ proj.getLink_truview()
+ "','"
+ proj.getImage()
+ "','"
+ proj.getSurvey_date()
+ "','"
+ proj.getTotal_lidar_returns() + "');";
System.out.println("PUKAO1");
try {
System.out.println("PUKAO2");
stmt.executeUpdate(sql);
c.commit();
} catch (SQLException e) {
System.out.println("PUKAO3");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ArrayList<Project> qSelect(String strQuery) {
Statement stmt = null;
ArrayList<Project> projects = new ArrayList<Project>();
Project project_temp = null;
try {
stmt = c.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT * FROM DIPLOMSKI_PROJEKTI;");
while (rs.next()) {
Integer id = rs.getInt("id");
String name = rs.getString("name");
String ot_collection_id = rs.getString("ot_collection_id");
String doi = rs.getString("doi");
String aka = rs.getString("aka");
String collection_platform = rs
.getString("collection_platform");
String dataset_overwiew = rs.getString("dataset_overwiew");
String dataset_acknowledgement = rs
.getString("dataset_acknowledgement");
String keywords = rs.getString("keywords");
String survey_date = rs.getString("survey_date");
String funder = rs.getString("funder");
String collector = rs.getString("collector");
String total_lidar_returns = rs
.getString("total_lidar_returns(pts)");
double point_density = rs
.getDouble("point_density(pts_per_m2)");
double area = rs.getDouble("area(km2)");
double x_coordinate = rs.getDouble("x_coordinate");
double y_coordinate = rs.getDouble("y_coordinate");
String coordinates_system = rs.getString("coordinates_system");
String link_truview = rs.getString("link_truview");
String image = rs.getString("image");
project_temp = new Project();
project_temp.setId(id);
project_temp.setName(name);
project_temp.setOt_collection_id(ot_collection_id);
project_temp.setDoi(doi);
project_temp.setAka(aka);
project_temp.setCollection_platform(collection_platform);
project_temp.setDataset_overwiew(dataset_overwiew);
project_temp.setDataset_acknowledgement(dataset_acknowledgement);
project_temp.setKeywords(keywords);
project_temp.setSurvey_date(survey_date);
project_temp.setFunder(funder);
project_temp.setCollector(collector);
project_temp.setCollection_platform(collection_platform);
project_temp.setTotal_lidar_returns(total_lidar_returns);
project_temp.setArea(area);
project_temp.setPoint_density(point_density);
project_temp.setX_coordinate(x_coordinate);
project_temp.setY_coordinate(y_coordinate);
project_temp.setCoordinates_system(coordinates_system);
project_temp.setLink_truview(link_truview);
project_temp.setImage(image);
projects.add(project_temp);
}
rs.close();
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return projects;
}
public boolean projectExist(Integer id) {
DBConnector dbConn = DBConnector.getInstance();
ArrayList<Project> projects = dbConn.qSelect(null);
for (int i = 0; i < projects.size(); i++) {
if (projects.get(i).getId() == id)
return true;
}
return false;
}
public Project returnProject(Integer id) {
DBConnector dbConn = DBConnector.getInstance();
ArrayList<Project> projects = dbConn.qSelect(null);
for (int i = 0; i < projects.size(); i++)
if (projects.get(i).getId() == id)
return projects.get(i);
return null;
}
}
由于异常说明,您不能在insert SQL语句中使用“(”符号作为列列表的一部分(即area(KM2)、POINT_DENSITY(PTS_PER_M2)
)。
我已经为我的城市选项卡创建了ajax代码,以显示来自ajax的相应城市数据。 我使用了以下代码: 下面是我要在ajax内容上加载的div 现在我已经使用以下jquery插件对我的项目进行分页http://cssglobe.com/post/9801/easy-paginate-jQuery-plugin-for-pagination 但是当我在ajax响应中使用它时,分页不起作用。 你能帮我一下我
今天我对封装感兴趣,对此我有一个基本问题。我理解为什么需要为私有字段添加setter和getter方法。但我看到为public int编写,字符串是其他的setter和getter。为什么我们需要为公共字段添加属性?我已经可以从任何地方访问公共变量。你怎么能用塞特和盖特控制我?谢谢
这是我的配置类。 这是我的出版商课 我正在犯错误。 2020-10-04 14:28:24.628错误17008 --- [ 127.0.0.1:5672]o. s. a. r. c.CachingConnectionFactory:通道关闭:通道错误;协议方法:#方法
null 现在我是否感到困惑:如果我想访问中的第一个字符并将其存储在eax寄存器中,我希望汇编程序执行如下操作: 如果我需要访问存储在ARGV[1]中的第二个字符并将其存储在eax寄存器中,我希望汇编程序执行如下操作: 但相反,我看到编译器执行以下操作: null
问题内容: 我将稍微解释一下我的脚本,以便您可以理解我的问题。 基本上我做了一个脚本来检查SOCKS5是还是。 当我在上面测试我的脚本时,它运行良好,但是当我在Windows上对其进行测试时,直到我将以下行添加到: 谁能向我解释为什么我在Windows中需要此行,而在Linux服务器上却不需要? 问题答案: SSL证书上的此cURL手册页介绍了连接到SSL / TLS受保护主机时 证书验证 的过程
问题内容: 我知道String [] args是作为参数传递给main的字符串数组。 但是,当您不将其包含为参数时(即使您不使用它),它也会引发异常。那么为什么需要它呢?另外,为什么不能是int []或boolean []? 问题答案: 这是一个字符串,因为命令行以文本形式表示。如果要将文本转换为整数或布尔值,则必须自己做- 操作系统或Java引导程序如何确切知道您希望如何解析所有内容?我想Jav