· 6 years ago · Mar 13, 2019, 03:50 PM
1protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
2 MysqlDataSource ds = new MysqlConnectionPoolDataSource();
3 ds.setServerName("localhost");
4 ds.setPort(3306);
5 ds.setUser("root");
6 ds.setPassword("");
7 try {
8 Connection connection = null ;
9 connection = ds.getConnection();
10 Statement statement = connection.createStatement();
11 // create the DB ..
12 statement.executeUpdate("CREATE DATABASE IF NOT EXISTS "
13 +"testSQLtable" ) ;
14
15 // use DB ..
16
17 statement.executeUpdate("USE testSQLtable") ;
18
19 // create table ...
20 statement.executeUpdate("DROP TABLE IF EXISTS account "
21 +"CREATE TABLE account ( "
22 +"accountNum INT( 11 ),"
23 +"dateCreated DATE NOT NULL,"
24 +"accountName TEXT,"
25 +"description TEXT,"
26 +"statusAccount TEXT,"
27 +"sumOfMoney INT( 11 ) NOT NULL DEFAULT 0 );" ) ;
28 } catch (SQLException e) {
29 // TODO Auto-generated catch block
30 e.printStackTrace();
31 }
32 }
33
34com.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 'CREATE TABLE account ( accountNum INT( 11 ),dateCreated DATE NOT NULL,accountNa' at line 1
35 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
36 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
37 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
38 at java.lang.reflect.Constructor.newInstance(Unknown Source)
39 at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
40 at com.mysql.jdbc.Util.getInstance(Util.java:386)
41 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
42 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
43 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
44 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
45 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
46 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2713)
47 at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1794)
48 at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1712)
49 at control.CreateDBinitialServlet.doGet(CreateDBinitialServlet.java:56)
50 at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
51 at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
52 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
53 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
54 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
55 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
56 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
57 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
58 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
59 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
60 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
61 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
62 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
63 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
64 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
65 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
66 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
67 at java.lang.Thread.run(Unknown Source)
68
69statement.executeUpdate("DROP TABLE IF EXISTS account ");
70statement.executeUpdate("CREATE TABLE account ( "
71 +"accountNum INT( 11 ),"
72 +"dateCreated DATE NOT NULL,"
73 +"accountName TEXT,"
74 +"description TEXT,"
75 +"statusAccount TEXT,"
76 +"sumOfMoney INT( 11 ) NOT NULL DEFAULT 0 )" ) ;
77
78statement.addBatch("DROP TABLE IF EXISTS account ");
79statement.addBatch("CREATE TABLE account ( "
80 +"accountNum INT( 11 ),"
81 +"dateCreated DATE NOT NULL,"
82 +"accountName TEXT,"
83 +"description TEXT,"
84 +"statusAccount TEXT,"
85 +"sumOfMoney INT( 11 ) NOT NULL DEFAULT 0 )" ) ;
86statement.executeBatch();
87
88statement.executeUpdate("DROP TABLE IF EXISTS account; "
89 +"CREATE TABLE account ( "
90 +"accountNum INT( 11 ),"
91 +"dateCreated DATE NOT NULL,"
92 +"accountName TEXT,"
93 +"description TEXT,"
94 +"statusAccount TEXT,"
95 +"sumOfMoney INT( 11 ) NOT NULL DEFAULT 0 );" ) ;
96
97statement.executeUpdate("DROP TABLE IF EXISTS account");
98 statement.executeUpdate("CREATE TABLE account ("
99 +"accountNum INT( 11 ),"
100 +"dateCreated DATE NOT NULL,"
101 +"accountName TEXT,"
102 +"description TEXT,"
103 +"statusAccount TEXT,"
104 +"sumOfMoney INT( 11 ) NOT NULL DEFAULT 0 );" ) ;