Re: [Lift] Re: How to use prepareStatement to select *** from DB (two db vender)?
What is wrong with: DB.use(FirstDB) { firstConnection = DB.use(SecondDB) { secondConnection = // do transactional query between two DBs here } } Note that DB.use nests such that the transaction will only be committed when the last DB.use block for a given ConnectionIdentifier is exited. On Thu, Jan 21, 2010 at 3:17 AM, Neil.Lv anim...@gmail.com wrote: I have added the demo code on the Github now. ( Mabye it's a bug with DB.runQuery and DB.use in the two db vender ) Here is the address: http://github.com/anim510/two_db_demo Thanks very much! Cheers, Neil On Jan 21, 11:26 am, Neil.Lv anim...@gmail.com wrote: My email is : anim...@gmail.com On Jan 21, 11:17 am, Neil.Lv anim...@gmail.com wrote: Mabye it's a bug with DB.runQuery and DB.use in the two db vender Two question: (problem) 1: I don't know why the HelloWorld snippet code will be execute 2 times in this code. (See the HelloWorld.scala file.) 2: The dbDefaultConnectionIdentifier method in the Model that it works fine when using Mapper's method such as ModelName.findAll(), it doesn't work when using DB.runQuery and DB.use(...) --- (Maybe it can't find the default db identifier) The question 2 I test it many times that found this problem. In the test app , the Hot.getHots2 and Hot.getHots3 method can't work. I comment the code now in the HelloWorld.scala file, you can try it. I can push the code on the github, and get this errors fatal: unable to fork So If anyone know what's wrong with it and I can send the demo.tar file through the email. Thanks very much! Cheers, Neil On Jan 21, 1:56 am, Neil.Lv anim...@gmail.com wrote: The DB.runQuery can works now, but the DB.prepareStatement also cant' work. Here is the test app address: http://github.com/anim510/two_db_demo Cheers, Neil On Jan 21, 1:16 am, Neil.Lv anim...@gmail.com wrote: Thank you very much, But it doesn't work yet, maybe because of using two db connections. I'll test it later again. On Jan 21, 12:44 am, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: Neil.Lv anim...@gmail.com writes: Hi all, I use two db connections in my app, and I want to use DB.prepareStatement to select the records from the second db. It failed, Here is the code: ### def getHotByTid(id : Long) = DB.use(bootstrap.liftweb.TwoDB) { conn = DB.prepareStatement(SELECT * FROM hots WHERE id=? , conn) { stmt = stmt.setLong(1, id) Log.info(stmt : + stmt) // The information is correctly now, but after call executeUpdate method stmt.executeUpdate() } } Not sure what your problem is really, but I think you should use DB.runQuery to execute a select statement Ie val (_,result) = DB.runQuery(SELECT COUNT(*), contract_length FROM + vehicles_current v + WHERE v.account_id=? + GROUP BY contract_length + ORDER BY contract_length, List(42)) /Jeppe -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Surf the harmonics -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: How to use prepareStatement to select *** from DB (two db vender)?
It doesn't work is not sufficient to diagnose. What behavior did you get, and what were you expecting? Were there any errors, log messages, exceptions, etc? If so, please copy them. Finally, if you have a reproducible test case please post it to github. I note earlier in the thread that you were fiddling with github, so if an older example is there, please make sure it's up to date with the most recent code. Thanks, -Ross On Jan 21, 2010, at 12:29 PM, Neil.Lv wrote: The users table in the OneDB, and the hots table in the TwoDB, they are separated! I have changed the method that like this: ### # I specify the TwoDB for hots table. override def dbDefaultConnectionIdentifier = bootstrap.liftweb.TwoDB def getHots3(id : Long) = { DB.use(bootstrap.liftweb.OneDB) { firstConn = DB.use(bootstrap.liftweb.TwoDB) { conn = DB.prepareStatement(SELECT * FROM hots WHERE id?, conn) { stmt = stmt.setLong(1, id) stmt.executeUpdate() } } } } ### But it doesn't work. Thanks very much! :) Cheers, Neil On Jan 22, 12:49 am, David Pollak feeder.of.the.be...@gmail.com wrote: What is wrong with: DB.use(FirstDB) { firstConnection = DB.use(SecondDB) { secondConnection = // do transactional query between two DBs here } } Note that DB.use nests such that the transaction will only be committed when the last DB.use block for a given ConnectionIdentifier is exited. On Thu, Jan 21, 2010 at 3:17 AM, Neil.Lv anim...@gmail.com wrote: I have added the demo code on the Github now. ( Mabye it's a bug with DB.runQuery and DB.use in the two db vender ) Here is the address: http://github.com/anim510/two_db_demo Thanks very much! Cheers, Neil On Jan 21, 11:26 am, Neil.Lv anim...@gmail.com wrote: My email is : anim...@gmail.com On Jan 21, 11:17 am, Neil.Lv anim...@gmail.com wrote: Mabye it's a bug with DB.runQuery and DB.use in the two db vender Two question: (problem) 1: I don't know why the HelloWorld snippet code will be execute 2 times in this code. (See the HelloWorld.scala file.) 2: The dbDefaultConnectionIdentifier method in the Model that it works fine when using Mapper's method such as ModelName.findAll(), it doesn't work when using DB.runQuery and DB.use(...) --- (Maybe it can't find the default db identifier) The question 2 I test it many times that found this problem. In the test app , the Hot.getHots2 and Hot.getHots3 method can't work. I comment the code now in the HelloWorld.scala file, you can try it. I can push the code on the github, and get this errors fatal: unable to fork So If anyone know what's wrong with it and I can send the demo.tar file through the email. Thanks very much! Cheers, Neil On Jan 21, 1:56 am, Neil.Lv anim...@gmail.com wrote: The DB.runQuery can works now, but the DB.prepareStatement also cant' work. Here is the test app address: http://github.com/anim510/two_db_demo Cheers, Neil On Jan 21, 1:16 am, Neil.Lv anim...@gmail.com wrote: Thank you very much, But it doesn't work yet, maybe because of using two db connections. I'll test it later again. On Jan 21, 12:44 am, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: Neil.Lv anim...@gmail.com writes: Hi all, I use two db connections in my app, and I want to use DB.prepareStatement to select the records from the second db. It failed, Here is the code: ### def getHotByTid(id : Long) = DB.use(bootstrap.liftweb.TwoDB) { conn = DB.prepareStatement(SELECT * FROM hots WHERE id=? , conn) { stmt = stmt.setLong(1, id) Log.info(stmt : + stmt) // The information is correctly now, but after call executeUpdate method stmt.executeUpdate() } } Not sure what your problem is really, but I think you should use DB.runQuery to execute a select statement Ie val (_,result) = DB.runQuery(SELECT COUNT(*), contract_length FROM + vehicles_current v + WHERE v.account_id=? + GROUP BY contract_length + ORDER BY contract_length, List(42)) /Jeppe -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=en. -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Surf the harmonics -- You
Re: [Lift] Re: How to use prepareStatement to select *** from DB (two db vender)?
On Thu, Jan 21, 2010 at 9:29 AM, Neil.Lv anim...@gmail.com wrote: The users table in the OneDB, and the hots table in the TwoDB, they are separated! I have changed the method that like this: ### # I specify the TwoDB for hots table. override def dbDefaultConnectionIdentifier = bootstrap.liftweb.TwoDB def getHots3(id : Long) = { DB.use(bootstrap.liftweb.OneDB) { firstConn = DB.use(bootstrap.liftweb.TwoDB) { conn = DB.prepareStatement(SELECT * FROM hots WHERE id?, conn) { stmt = stmt.setLong(1, id) stmt.executeUpdate() } } } } ### But it doesn't work. What do it doesn't work mean? Does it not compile, if not, what's the compilation error? If it's another error, what's the error? In your example, you are not using the firstConn connection. Also, you will get an exception if you do an executeUpdate with a SELECT statement (this is JDBC, not Lift). You must do an executeQuery for a SELECT. Thanks very much! :) Cheers, Neil On Jan 22, 12:49 am, David Pollak feeder.of.the.be...@gmail.com wrote: What is wrong with: DB.use(FirstDB) { firstConnection = DB.use(SecondDB) { secondConnection = // do transactional query between two DBs here } } Note that DB.use nests such that the transaction will only be committed when the last DB.use block for a given ConnectionIdentifier is exited. On Thu, Jan 21, 2010 at 3:17 AM, Neil.Lv anim...@gmail.com wrote: I have added the demo code on the Github now. ( Mabye it's a bug with DB.runQuery and DB.use in the two db vender ) Here is the address: http://github.com/anim510/two_db_demo Thanks very much! Cheers, Neil On Jan 21, 11:26 am, Neil.Lv anim...@gmail.com wrote: My email is : anim...@gmail.com On Jan 21, 11:17 am, Neil.Lv anim...@gmail.com wrote: Mabye it's a bug with DB.runQuery and DB.use in the two db vender Two question: (problem) 1: I don't know why the HelloWorld snippet code will be execute 2 times in this code. (See the HelloWorld.scala file.) 2: The dbDefaultConnectionIdentifier method in the Model that it works fine when using Mapper's method such as ModelName.findAll(), it doesn't work when using DB.runQuery and DB.use(...) --- (Maybe it can't find the default db identifier) The question 2 I test it many times that found this problem. In the test app , the Hot.getHots2 and Hot.getHots3 method can't work. I comment the code now in the HelloWorld.scala file, you can try it. I can push the code on the github, and get this errors fatal: unable to fork So If anyone know what's wrong with it and I can send the demo.tar file through the email. Thanks very much! Cheers, Neil On Jan 21, 1:56 am, Neil.Lv anim...@gmail.com wrote: The DB.runQuery can works now, but the DB.prepareStatement also cant' work. Here is the test app address: http://github.com/anim510/two_db_demo Cheers, Neil On Jan 21, 1:16 am, Neil.Lv anim...@gmail.com wrote: Thank you very much, But it doesn't work yet, maybe because of using two db connections. I'll test it later again. On Jan 21, 12:44 am, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: Neil.Lv anim...@gmail.com writes: Hi all, I use two db connections in my app, and I want to use DB.prepareStatement to select the records from the second db. It failed, Here is the code: ### def getHotByTid(id : Long) = DB.use(bootstrap.liftweb.TwoDB) { conn = DB.prepareStatement(SELECT * FROM hots WHERE id=? , conn) { stmt = stmt.setLong(1, id) Log.info(stmt : + stmt) // The information is correctly now, but after call executeUpdate method stmt.executeUpdate() } } Not sure what your problem is really, but I think you should use DB.runQuery to execute a select statement Ie val (_,result) = DB.runQuery(SELECT COUNT(*), contract_length FROM + vehicles_current v + WHERE v.account_id=? + GROUP BY contract_length + ORDER BY contract_length, List(42)) /Jeppe -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send
Re: [Lift] Re: How to use prepareStatement to select *** from DB (two db vender)?
'mvn clean' deletes them for you. - Neil.Lvanim...@gmail.com wrote: Thanks guys very very much! I'm using the Windows XP, I reset the height buffer for the CMD now, and can see the full error message now. The code can work fine now ( it's so strange that I run this code on the another computer , and it's all OK... ) Maybe I need to delete all the target files. :) Cheers, Neil On Jan 22, 3:09 am, Naftoli Gugenheim naftoli...@gmail.com wrote: If you are using Windows and CMD.EXE does not hold enough lines to view the error, click the control menu of the CMD window and click Properties, then on the Layout tab you set the height of the screen buffer size. - Neil.Lvanim...@gmail.com wrote: Here is the lastest code now, g...@github.com:anim510/two_db_demo.git start server and visit:http://localhost:8080/and get this error, In the cmd I can't see all the error message, here is the all the message on the cmd screen. at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1$$an onfun$apply$72.apply(LiftSession.scala:1041) at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1$$an onfun$apply$72.apply(LiftSession.scala:1041) at net.liftweb.http.LiftSession.net$liftweb$http$LiftSession$ $processOrD efer(LiftSession.scala:1026) at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1.app ly(LiftSession.scala:1040) at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1.app ly(LiftSession.scala:1034) at scala.Seq$class.flatMap(Seq.scala:294) at scala.xml.NodeSeq.flatMap(NodeSeq.scala:34) at net.liftweb.http.LiftSession.processSurroundAndInclude (LiftSession.sc ala:1033) at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1.app ly(LiftSession.scala:1054) at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1.app ly(LiftSession.scala:1034) at scala.Seq$class.flatMap(Seq.scala:294) at scala.xml.NodeSeq.flatMap(NodeSeq.scala:34) at net.liftweb.http.LiftSession.processSurroundAndInclude (LiftSession.sc ala:1033) at net.liftweb.builtin.snippet.Surround$$anonfun$render$1$ $anonfun$apply $2.apply(Surround.scala:37) at net.liftweb.builtin.snippet.Surround$$anonfun$render$1$ $anonfun$apply $2.apply(Surround.scala:34) at net.liftweb.common.Full.map(Box.scala:330) at net.liftweb.builtin.snippet.Surround$$anonfun$render$1.apply (Surround .scala:34) at net.liftweb.builtin.snippet.Surround$$anonfun$render$1.apply (Surround .scala:33) at net.liftweb.common.Full.flatMap(Box.scala:332) at net.liftweb.builtin.snippet.Surround$.render(Surround.scala: 33) at net.liftweb.builtin.snippet.Surround$$anonfun$dispatch$1$ $anonfun$app ly$1.apply(Surround.scala:29) at net.liftweb.builtin.snippet.Surround$$anonfun$dispatch$1$ $anonfun$app ly$1.apply(Surround.scala:29) at net.liftweb.http.LiftSession$$anonfun$18$$anonfun$apply$58$ $anonfun$a pply$61$$anonfun$apply$63.apply(LiftSession.scala:846) at net.liftweb.http.LiftSession$$anonfun$18$$anonfun$apply$58$ $anonfun$a pply$61$$anonfun$apply$63.apply(LiftSession.scala:830) at net.liftweb.common.EmptyBox.openOr(Box.scala:372) at net.liftweb.http.LiftSession$$anonfun$18$$anonfun$apply$58$ $anonfun$a pply$61.apply(LiftSession.scala:830) at net.liftweb.http.LiftSession$$anonfun$18$$anonfun$apply$58$ $anonfun$a pply$61.apply(LiftSession.scala:830) at net.liftweb.common.EmptyBox.openOr(Box.scala:372) at net.liftweb.http.LiftSession$$anonfun$18$$anonfun$apply $58.apply(Lift Session.scala:829) at net.liftweb.http.LiftSession$$anonfun$18$$anonfun$apply $58.apply(Lift Session.scala:829) at net.liftweb.http.S$.doSnippet(S.scala:1677) at net.liftweb.http.LiftSession$$anonfun$18.apply (LiftSession.scala:827) at net.liftweb.http.LiftSession$$anonfun$18.apply (LiftSession.scala:826) at net.liftweb.common.Full.map(Box.scala:330) at net.liftweb.http.LiftSession.net$liftweb$http$LiftSession$ $processSni ppet(LiftSession.scala:826) at net.liftweb.http.LiftSession$$anonfun $_defaultLiftTagProcessing$1.app ly(LiftSession.scala:942) at net.liftweb.http.LiftSession$$anonfun $_defaultLiftTagProcessing$1.app ly(LiftSession.scala:930) at net.liftweb.util.NamedPF.apply(NamedPartialFunction.scala: 33) at net.liftweb.util.NamedPF$.apply(NamedPartialFunction.scala: 79) at net.liftweb.http.LiftSession$$anonfun $processSurroundAndInclude$1$$an onfun$apply$72$$anonfun$apply$73$$anonfun$apply$74$$anonfun$apply $75.apply(LiftS ession.scala:1044) at