จากนั้นก็ส่งเมลส์ไปหา host พร้อมกับ war file ทาง host ก็แจ้งมาว่ามีปัญหา "Application at context path /webbudsa could not be started" ทำให้ผมต้องหาสาเหตุ ก็ปรากฏว่า สาเหตุมาจาก การเรียง
Tuesday, April 29, 2014
web.xml มีปัญหา Application at context path /webbudsa could not be started
วันนี้ได้ทำการ upload web app ไปที่โฮส ปรากฏว่าไม่ได้ น่าจะเกิดจาก time out
จากนั้นก็ส่งเมลส์ไปหา host พร้อมกับ war file ทาง host ก็แจ้งมาว่ามีปัญหา "Application at context path /webbudsa could not be started" ทำให้ผมต้องหาสาเหตุ ก็ปรากฏว่า สาเหตุมาจาก การเรียง กับ สะเปะสะปะ อาจจะเนื่องจากผมได้ทำการเขียนบน tomcat 7 ซึ่งน่าจะฉลาดกว่า tomcat 6(บน host) ทำให้สามารถทำงานได้ปกติในระหว่างการเขียนโปรแกรม แต่เมื่อ upload บน host จริงๆกลับมีปัญหาดังกล่าวก็เป็นได้ จึงต้องทำการเรียงซะให้ โดยเรียง ก่อน แล้วตามด้วย ทีหลัง ก็เป็นอันเรียบร้อย
จากนั้นก็ส่งเมลส์ไปหา host พร้อมกับ war file ทาง host ก็แจ้งมาว่ามีปัญหา "Application at context path /webbudsa could not be started" ทำให้ผมต้องหาสาเหตุ ก็ปรากฏว่า สาเหตุมาจาก การเรียง
Wednesday, January 22, 2014
ไดรเวอร์ printer เครื่องลูก
วันนี้ผมได้ลง window 7 64 bit ที่เครื่องแม่ เมื่อลงเสร็จแล้ว เครื่องลูกจะทำการ print แต่ไม่ได้เนื่องจากว่าในเครื่องแม่นั้น ไม่มี driver 32 bit ทำให้เครื่องลูกไม่สามารถปริ้นได้
ทางแก้
ที่ปริ้นเตอร์เราสามารถเลือก driver 32 เพิ่มเข้าไปได้(เครื่องแม่) window ก็จะถาม driver 32 bit จากนั้นก็หา driver ของ printer มาลง และ window ก็จะถาม ntprint.inf อันนี้ไปหามาจากเครื่องที่ลง window 32 bit มา เท่านี้ก็เสร็จ
ทางแก้
ที่ปริ้นเตอร์เราสามารถเลือก driver 32 เพิ่มเข้าไปได้(เครื่องแม่) window ก็จะถาม driver 32 bit จากนั้นก็หา driver ของ printer มาลง และ window ก็จะถาม ntprint.inf อันนี้ไปหามาจากเครื่องที่ลง window 32 bit มา เท่านี้ก็เสร็จ
Monday, December 16, 2013
ดึง Session ID จาก java มาไว้ที่ javascript
เนื่องจากผมจะต้องใช้ jsessionid ของ java มาใช้ในการแสดงผลภาพ captcha แต่ในตัวอย่างนั้นผมจะต้องใช้เป็น servlet แต่ผมไม่ต้องการใช้ อยากใช้แบบ Ajax DWR แทน เลยต้องหาค่า 2 ค่าก่อนส่งไปที่ class ของ jcaptcha นั่นคือ sessionid กับ ค่าที่ผู้ใช้เว็บป้อนเข้ามา ปัญหาคือจะหา sessionid ได้ยังไงส่วนค่าที่ผู้ใช้เว็บป้อนมานั้นง่ายเลยติดแค่ sessionid อย่างเดียว
หาอยู่ตั้งนานว่าจะทำไงโดยใช้ javascript แต่ก็ไม่ได้และยุ่งยากเกินไป ก็มาได้ง่ายๆด้วย java นี่แหละ(มัวแต่คิดถึง Ajax อย่างเดียวเลยลืมเพื่อนเก่าที่เป็น scriptlet ไปเลยนะเนี่ย) ง่่ายๆครับ คือ
ง่ายๆแค่นี้เลยโดยใช้ expression ใน jsp แค่เนี่ย หาอยู่ตั้งนาน แต่ไม่ได้เป็น object เป็น String อย่างเดียวแค่นั้น
หาอยู่ตั้งนานว่าจะทำไงโดยใช้ javascript แต่ก็ไม่ได้และยุ่งยากเกินไป ก็มาได้ง่ายๆด้วย java นี่แหละ(มัวแต่คิดถึง Ajax อย่างเดียวเลยลืมเพื่อนเก่าที่เป็น scriptlet ไปเลยนะเนี่ย) ง่่ายๆครับ คือ
ง่ายๆแค่นี้เลยโดยใช้ expression ใน jsp แค่เนี่ย หาอยู่ตั้งนาน แต่ไม่ได้เป็น object เป็น String อย่างเดียวแค่นั้น
Tuesday, April 9, 2013
mySQL error 121
วันนี้สร้างตารางขึ้นมาชื่อว่า booking โดยเป็น weak entity แบบ M:N ทีนี้สร้างในฐานข้อมูลจริงไม่ได้ เกิด error 121 เลยไปหาในเน็ตทางแก้คือเปลี่ยนชื่อ attribute ของ table booking ที่ fk ไป table อื่นซะ ลองดูในเว็บที่ฝรั่งถามไว้นะครับ
http://stackoverflow.com/questions/3316410/sql-error-errno-121
http://stackoverflow.com/questions/3316410/sql-error-errno-121
Thursday, March 28, 2013
การใช้ Transactions ใน Java
Disabling Auto-Commit Mode
เมื่อทำการสร้าง connection นั้น จะอยู่ในโหมด Auto Commit โดยอัตโนมัติ นั่นหมายถึงว่าแต่ละคำสั่ง SQL ที่กระทำ transaction นั้นจะ Commit(ยืนยัน) หมด(ถ้าจะให้ละเอียดคือ ในคำสั่ง SQL นั้นจะ Commit เมื่อมันเสร็จสิ้นแล้ว ไม่ใช่ในขณะทำงาน(excuted) )
ในการ disable commit คือ con.setAutoCommit(false);
หลังจากที่เราได้ทำการ disable commit ไปแล้วจะไม่มีคำสั่ง SQL Statement ไหน commit จนกว่าเราจะใช้คำสั่ง commit เอง คำสั่ง SQL ทั้งหมดจะถูก excute หลังจากเรียกคำสั่ง commit คือเพิ่มเข้าไปใน transection ปัจจุบันและ commit รวมกันเป็นกลุ่ม ดังตัวอย่าง
public void updateCoffeeSales(HashMapsalesForWeek) throws SQLException { PreparedStatement updateSales = null; PreparedStatement updateTotal = null; String updateString = "update " + dbName + ".COFFEES " + "set SALES = ? where COF_NAME = ?"; String updateStatement = "update " + dbName + ".COFFEES " + "set TOTAL = TOTAL + ? " + "where COF_NAME = ?"; try { con.setAutoCommit(false); updateSales = con.prepareStatement(updateString); updateTotal = con.prepareStatement(updateStatement); for (Map.Entry e : salesForWeek.entrySet()) { updateSales.setInt(1, e.getValue().intValue()); updateSales.setString(2, e.getKey()); updateSales.executeUpdate(); updateTotal.setInt(1, e.getValue().intValue()); updateTotal.setString(2, e.getKey()); updateTotal.executeUpdate(); con.commit(); } } catch (SQLException e ) { JDBCTutorialUtilities.printSQLException(e); if (con != null) { try { System.err.print("Transaction is being rolled back"); con.rollback(); } catch(SQLException excep) { JDBCTutorialUtilities.printSQLException(excep); } } } finally { if (updateSales != null) { updateSales.close(); } if (updateTotal != null) { updateTotal.close(); } con.setAutoCommit(true); } }
ใน method นี้จะ auto-commit mode เป็น disable ซึ่งหมายถึง 2 prepared statements จะ commit รวมกัน เมื่อ commit มีการเรียก
ในคำสั่ง con.setAutoCommit(true); จะหมายถึงการกลับไปยัง สถานะ default เมื่อคำสั่งต่างๆเสร็จสิ้้น
Using Transactions to Preserve Data Integrity
ตัวอย่างของ transaction isolation level คือTRANSACTION_READ_COMMITTED จะไม่ยอมรับการเข้าถึงข้อมูลจนกว่า transaction เสร็จสิ้น พูดอย่างอย่างคือ DBMS จะไม่ยอมรับการมี dirty reads เกิดขึ้นTransaction Isolation Level แบ่งออกเป็น 5 ระดับ ดังนี้
Isolation Level Transactions Dirty Reads Non-Repeatable Reads Phantom Reads TRANSACTION_NONENot supported Not applicable Not applicable Not applicable TRANSACTION_READ_COMMITTEDSupported Prevented Allowed Allowed TRANSACTION_READ_UNCOMMITTEDSupported Allowed Allowed Allowed TRANSACTION_REPEATABLE_READSupported Prevented Prevented Allowed TRANSACTION_SERIALIZABLESupported Prevented Prevented Prevented non-repeatable read เกิดขึ้นเมื่อ transaction A รับค่าแถว,ลำดับต่อมา transaction B update แถว และลำดับต่อมา transaction A รับค่าที่แถวเดิมอีกครั้ง transaction A รับค่าที่แถวเดิม 2 ครั้งแต่ได้ค่าต่างไปจากเดิมphantom read เกิดขึ้นเมื่อ transaction A รับค่าจะแถวโดยผ่าน condition (where),ลำดับต่อมา transaction B ก็ทำการเพิ่มและ update แถวโดยผ่าน condition เดียวกันกับ transaction A ต่อมา transaction A ก็มารับค่าตาม condition อีกครั้ง แต่ปรากฏว่าเห็นแถวเพิ่มขึ้น แถวที่เพิ่มขึ้นนี้เองเรียกว่า phantomโดยทั่วไปเราไม่ต้องทำอะไรเกี่ยวกับTransaction Isolation Level สามารถใช้ค่า defalut ของ DBMS ได้เลย ค่า default ของ DBMS จะขึ้นอยู่กับ DBMS ที่ใช้ เช่น Java DB คือTRANSACTION_READ_COMMITTED ถ้าต้องการหาว่า DBMS ใช้ Level ไหนใช้คำสั่งConnectionmethodgetTransactionIsolation และถ้าต้องการ set เองใช้ConnectionmethodsetTransactionIsolationNote JDBC driver อาจจะไม่ support transaction level ทั้งหมด ถ้าไม่ support level ที่ระบุในsetTransactionIsolation ก็สามารถสลับไปใช้ level ที่สูงกว่า ถ้า driver ไม่สามารถสลับไปที่ level ที่สูงกว่าได้จะเกิด SQLException ใช้ methodDatabaseMetaData.supportsTransactionIsolationLevel ในการหาว่า driver support level ไหนSetting and Rolling Back to Savepoints
methodConnection.setSavepoint คือ set Savepoint Object ใน transaction ปัจจุบันConnection.rollbackmethod คือส่ง Savepoint ไปเป็น agumentตัวอย่างถ้าต้องการเพิ่มราคาแล้วราคานั้นเกินกว่าที่กำหนดไว้ก็จะ rollback ไปค่าเริ่มต้นใหม่อีกครั้งpublic void modifyPricesByPercentage( String coffeeName, float priceModifier, float maximumPrice) throws SQLException { con.setAutoCommit(false); Statement getPrice = null; Statement updatePrice = null; ResultSet rs = null; String query = "SELECT COF_NAME, PRICE FROM COFFEES " + "WHERE COF_NAME = '" + coffeeName + "'"; try { Savepoint save1 = con.setSavepoint(); getPrice = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); updatePrice = con.createStatement(); if (!getPrice.execute(query)) { System.out.println( "Could not find entry " + "for coffee named " + coffeeName); } else { rs = getPrice.getResultSet(); rs.first(); float oldPrice = rs.getFloat("PRICE"); float newPrice = oldPrice + (oldPrice * priceModifier); System.out.println( "Old price of " + coffeeName + " is " + oldPrice); System.out.println( "New price of " + coffeeName + " is " + newPrice); System.out.println( "Performing update..."); updatePrice.executeUpdate( "UPDATE COFFEES SET PRICE = " + newPrice + " WHERE COF_NAME = '" + coffeeName + "'"); System.out.println( "\nCOFFEES table after " + "update:"); CoffeesTable.viewTable(con); if (newPrice > maximumPrice) { System.out.println( "\nThe new price, " + newPrice + ", is greater than the " + "maximum price, " + maximumPrice + ". Rolling back the " + "transaction..."); con.rollback(save1); System.out.println( "\nCOFFEES table " + "after rollback:"); CoffeesTable.viewTable(con); } con.commit(); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (getPrice != null) { getPrice.close(); } if (updatePrice != null) { updatePrice.close(); } con.setAutoCommit(true); } }method เริ่มต้นโดยสร้าง Savepoint ด้วยคำสั่ง Savepoint save1 = con.setSavepoint();method จะทำการตรวจสอบค่า new price ว่ามากกว่า maximum price หรือไม่ถ้ามากกว่าก็ให้กลับไปค่าปัจจุบัน con.rollback(save1);ดังนั้น เมื่อ method commit transaction โดยเรียกConnection.commitmethod มันจะไม่ commit แถวใดๆที่มีความสัมพันธ์กับ Savepoint ที่มีการ rolled back มันจะ commit แถวอื่นReleasing Savepoints
methodConnection.releaseSavepoint โดยป้อน Savepoint Object เป็น parameter และจะ remove Savepoint จาก transaction ปัจจุบันSavepoint จะ Release โดยอัตโนมัติ เมื่อมีการ commit หรือเมื่อ transaction rolle backการเรียน method rollback จะทำให้ออกจาก transaction และทำการ return ค่าใดที่ทำการเปลียนแปลงก่อนหน้าให้เป็นค่าเริ่มต้น ถ้าคุณทดลอง execute statment ใน transaction จะทำให้เกิด SQLException การเรียก method จะทำให้ transaction จบ และทำการเริ่มต้น transacton ใหม่อีกครั้ง
Saturday, December 1, 2012
deep freeze v.7 ไม่เห็นใน Task bar
ผมได้ทำการแช่แข็ง Harddisk ไว้ แล้วทีนี้จะทำการแก้ไข window นิดนึงจึงทำการปลดล็อคแต่ปรากฎว่า
ปลดล็อกไม่ได้ เนื่องจาก ไม่เห็นรูปไอคอน deep freeze "มันหายไปไหนเนี่ย" หาอยู่ตั้งนานว่าจะทำไง เกือบลง window ใหม่แล้วเชียว ไปพบวิธีแก้ซะก่อน คือ
-ให้ทำการ logout ก่อนนะ
-จากนั้นก็เข้า window ใหม่ ไม่ต้อง boot เครื่องใหม่นะกดเข้าไปเลย
ก็จะเห็น deep freeze และก็จัดการได้เลย ง่ายซะไม่มี
ปลดล็อกไม่ได้ เนื่องจาก ไม่เห็นรูปไอคอน deep freeze "มันหายไปไหนเนี่ย" หาอยู่ตั้งนานว่าจะทำไง เกือบลง window ใหม่แล้วเชียว ไปพบวิธีแก้ซะก่อน คือ
-ให้ทำการ logout ก่อนนะ
-จากนั้นก็เข้า window ใหม่ ไม่ต้อง boot เครื่องใหม่นะกดเข้าไปเลย
ก็จะเห็น deep freeze และก็จัดการได้เลย ง่ายซะไม่มี
Sunday, April 15, 2012
JavaScript undefined Properties
เป็นการระบุว่า ไม่มีการกำหนดค่าให้กับตัวแปร ดังตัวอย่าง
ได้ผลลัพธ์คือ
t2 is undefined
จะเห็นได้ว่า ตัวแปร t2 ยังไม่ได้กำหนดค่าให้ทำให้มีคุณสมบัติเป็น undefined
ได้ผลลัพธ์คือ
t2 is undefined
จะเห็นได้ว่า ตัวแปร t2 ยังไม่ได้กำหนดค่าให้ทำให้มีคุณสมบัติเป็น undefined
Subscribe to:
Posts (Atom)