java · mysql

run linux command from java and reading result?

import java.*; class Test { public static void main(String[] args) { int ch; try { Process myProcess = Runtime.getRuntime().exec(“ls -al”); InputStreamReader myIStreamReader = new InputStreamReader(myProcess.getInputStream()); while ((ch = myIStreamReader.read()) != -1) { System.out.print((char) ch); } } catch (IOException anIOException) { System.out.println(anIOException); } } }

java · jdbc · mysql

SqlExecuter vs JDBC

public class CmdExec { public static void main(String argv[]) { executeSql(); } private static void executeSql() { final class SqlExecuter extends SQLExec { public SqlExecuter() { Project project = new Project(); project.init(); setProject(project); // setTaskType(“sql”); setTaskName(“sql”); } } SqlExecuter executer = new SqlExecuter(); executer.setSrc(new File(“/home/admin/Obama/scripfile.sql”)); executer.setDriver(“com.mysql.jdbc.Driver”); executer.setPassword(“root”); executer.setUserid(“root”); executer.setUrl(“jdbc:mysql://localhost:3306/Central_Share”); executer.execute(); } } //add dependency <dependency>… Continue reading SqlExecuter vs JDBC

java · jdbc · mysql

how to get last insert id by java

public static int getLastInsertID(Connection conn, String statment)throws SQLException { int lastInsertedId = -1; PreparedStatement ps = conn.prepareStatement(statment,PreparedStatement.RETURN_GENERATED_KEYS); ps.executeUpdate(); ResultSet rskey = ps.getGeneratedKeys(); if (rskey != null && rskey.next()) { lastInsertedId = rskey.getInt(1); } return lastInsertedId; }

mysql · Uncategorized

How to find and replace in mysql

To find a string in a certain field and replace it with another string: update [table_name] set [field_name] = replace([field_name],'[string_to_find]’,'[string_to_replace]’);   update `wp_posts` set `post_content` = replace(`post_content`,’http://localhost/elrashd/holding/&#8217;,’http://elrashad.promolinks.com/&#8217;)

database · mysql

unknown-table-engine-innodb

http://www.osterman.com/wordpress/2007/12/23/unknown-table-engine-innodb   I was getting the error “ERROR 1286 (42000): Unknown table engine ‘InnoDB’” when trying to create/alter tables with the InnoDB engine. You can check for this warning by issuing the create or alter statements and then running show warnings; in the same mysql client session. Check if you have InnoDB support enabled: mysql>… Continue reading unknown-table-engine-innodb