Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过java将问题插入数据库_Java_Postgresql_Jdbc - Fatal编程技术网

通过java将问题插入数据库

通过java将问题插入数据库,java,postgresql,jdbc,Java,Postgresql,Jdbc,我在数据库中插入一些数据时有点问题。CSV解析器正在读取数据并将其更改为数据。除此之外,我继续收到以下错误消息: Connected to the PostgreSQL server successfully. Naam van de garage: P_Erasmusbrug, Longditude: 4.482313155, Latitude: 51.91024645 org.postgresql.util.PSQLException: The column index is out of

我在数据库中插入一些数据时有点问题。CSV解析器正在读取数据并将其更改为数据。除此之外,我继续收到以下错误消息:

Connected to the PostgreSQL server successfully.
Naam van de garage: P_Erasmusbrug, Longditude: 4.482313155, Latitude: 51.91024645
org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:65)
at org.postgresql.core.v3.SimpleParameterList.setStringParameter(SimpleParameterList.java:128)
at org.postgresql.jdbc.PgPreparedStatement.bindString(PgPreparedStatement.java:1023)
at org.postgresql.jdbc.PgPreparedStatement.setString(PgPreparedStatement.java:374)
at org.postgresql.jdbc.PgPreparedStatement.setString(PgPreparedStatement.java:358)
at Database.ConnectDatabase.parser(ConnectDatabase.java:80)
at Events.CSVReader.main(CSVReader.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Thank you for your service.
Naam van de garage: P_St.Jacobsplaats, Longditude: 4.482054381, Latitude: 51.92410235
Thank you for your service.
Naam van de garage: P_Schouwburgplein, Longditude: 4.473618335, Latitude: 51.92102728
org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
对于所有其他数据行,这将继续。有没有办法解决这个问题,因为我真的不明白错误消息包括什么。。 a、b2和c2是“名称”、“londitude”和“纬度”的变量

包数据库;
导入java.io.*;
导入java.sql.*;
导入java.util.HashMap;
导入java.sql.SQLException;
公共类数据库{
私有最终字符串url=“jdbc:postgresql://localhost/Project3";
私有最终字符串user=“postgres”;
私有最终字符串密码=“kaas123”;
专用连接连接器;
公共连接连接(){
连接conn=null;
试一试{
conn=DriverManager.getConnection(url、用户、密码);
System.out.println(“已成功连接到PostgreSQL服务器”);
}捕获(SQLException异常){
System.out.println(exception.getMessage());
}
this.conn=conn;
返回连接;
}
公共HashMap getGarages(){
HashMap newHashMap=新HashMap();
试一试{
语句stmt=conn.createStatement();
结果集rs;
rs=stmt.executeQuery(“按deelgemente从车库组中选择deelgemente、COUNT(garagenaam));
while(rs.next()){
字符串deelgementenam=rs.getString(“deelgemente”);
double-garageNaamCount=rs.getDouble(“计数”);
newHashMap.put(Deelgementenaam,garageNaamCount);
}
}捕获(例外e){
System.err.println(“得到一个异常!”);
System.err.println(e.getMessage());
}
返回newHashMap;
}
公共哈希映射获取年份(整数年){
HashMap newHashMap=新HashMap();
试一试{
语句stmt=conn.createStatement();
结果集rs;
rs=标准执行程序(“从autodiefstal中选择Deelgemente,percentagediefstal,其中jaar=“+年”);
while(rs.next()){
字符串deelgementenam=rs.getString(“deelgemente”);
double deelPercentage=rs.getDouble(“百分比值”);
newHashMap.put(deelgementenaam,deelPercentage);
}
}捕获(例外e){
System.err.println(“得到一个异常!”);
System.err.println(e.getMessage());
}
返回newHashMap;
}
公共int解析器(字符串a、浮点b2、浮点c2){
int=0;
连接conn=null;
PreparedStatement stmt=null;
试一试{
conn=DriverManager.getConnection(url、用户、密码);
String insertSQL=“插入testparser(garagenaam、xpos、ypos)值(“+a+”、“+b2+”、“+c2+”)”;
stmt=conn.prepareStatement(插入SQL);
stmt.setString(1,a);
stmt.setFloat(2,b2);
stmt.setFloat(3,c2);
System.out.println(“将数据插入数据库…”);
updated=stmt.executeUpdate();
}捕获(SQLSE异常){
se.printStackTrace();
}捕获(例外e){
e、 printStackTrace();
}最后{
试一试{
如果(stmt!=null)
康涅狄格州关闭();
}捕获(SQLSE异常){
}
试一试{
如果(conn!=null)
康涅狄格州关闭();
}捕获(SQLSE异常){
se.printStackTrace();
}
}
System.out.println(“感谢您的服务”);
this.conn=conn;
更新的回报;
}
}

您没有正确使用
占位符系统,请更换:

String insertSQL = "INSERT INTO testparser(garagenaam, xpos, ypos) VALUES(" + a + "," + b2 + "," + c2 + ")";


您没有正确使用
占位符系统,请更换:

String insertSQL = "INSERT INTO testparser(garagenaam, xpos, ypos) VALUES(" + a + "," + b2 + "," + c2 + ")";


删除了不兼容的mysql标记删除了不兼容的mysql标记非常感谢!:D我只需要更改“”???“”,我忘了它会立即用我的替换变量。我会在接下来的9分钟内接受你的答案,谢谢你的帮助=)非常感谢!:D我只需要更改“”???“”,我忘了它会立即用我的替换变量。我将在接下来的9分钟内接受您的答案,谢谢您的帮助=)
String insertSQL = "INSERT INTO testparser(garagenaam, xpos, ypos) VALUES(?,?,?)";