Note that there are some explanatory texts on larger screens.

plurals
  1. POJdbc and MySql not wanting to play nicely together
    primarykey
    data
    text
    <p>I have been working on a java application that has a connection to a mysql database. I can connect and run queries but when I try to take a string and run it as a sql query I get this error.</p> <pre><code>Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO usageData (`COMID`,`Year`,`Month`,`kwhr`,`co2`) VALUES ('15650', '2' at line 3 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583) </code></pre> <p>Bellow is the code that I'm using to connect to the database</p> <pre><code>public static void main(String[] args) throws Exception { String dbms = "mysql"; String serverName = "localhost"; String portNumber = "8889"; String DBName = "ConnectDatabase"; String user = "root"; String password = "root"; ArrayList&lt;Integer&gt; yearList = new ArrayList&lt;Integer&gt;(); ArrayList&lt;CustomerRecord&gt; customerRecordList = getCustomerRecords(args[0], yearList); ArrayList&lt;ClimateRecord&gt; climateRecordList = getClimateRecords(args[1]); StringBuffer buf = new StringBuffer(); for (CustomerRecord record : customerRecordList) { buf.append(customerRecord2SQL(record)); } for (int i = (climateRecordList.size() - 1); i &gt;= 0; i--) { //for (ClimateRecord record : climateRecordList) { ClimateRecord record = climateRecordList.get(i); buf.append(climateRecord2SQL(record)); } buf.append(cityStats(dbms,serverName,portNumber,DBName,user,password)); buf.append(zipStats(dbms,serverName,portNumber,DBName,user,password)); System.out.println(buf.toString()); //here is the code to go ahead and update the database Connection con = null; con = DriverManager.getConnection("jdbc:" + dbms + "://" + serverName + ":" + portNumber + "/" + DBName + "?user="+user+"&amp;password=" + password); Statement stmt = con.createStatement(); stmt.executeUpdate(buf.toString()); BufferedWriter out = new BufferedWriter(new FileWriter(args[2])); out.write(buf.toString()); out.close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload