import com.mysql.jdbc.jdbc2.optional.MysqlDataSource
import com.mysql.jdbc.*
import groovy.sql.*
/* the commented code works fine
MysqlDataSource ds = new MysqlDataSource()
ds.user = 'root'
ds.password = ""
ds.url = 'jdbc:mysql://localhost:3306/test'
Sql sql=Sql.newInstance(ds)
sql.close()
*/
d=Class.forName("com.mysql.jdbc.Driver").newInstance()
println d.class // class com.mysql.jdbc.Driver
Sql sql=Sql.newInstance(
'jdbc:mysql://localhost:3306/test',
'root',
"",
'com.mysql.jdbc.Driver'
)
Run Code Online (Sandbox Code Playgroud)
代码注释工作正常,我可以得到驱动程序的实例
但是当我使用
Sql sql=Sql.newInstance(
'jdbc:mysql://localhost:3306/test',
'root',
"",
'com.mysql.jdbc.Driver'
)
Run Code Online (Sandbox Code Playgroud)
它引发了一个例外:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
我无法解决它,是否有任何男孩来帮助我?
我不确定在编写scala代码时是否犯了一些错误。
问题是?
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
Run Code Online (Sandbox Code Playgroud)
博客(http://www.ituring.com.cn/article/111574)说他编写的代码haskell只包含6ms:
import Data.List
import Data.Char
main = do …Run Code Online (Sandbox Code Playgroud) 我写了代码,但看起来很难看.
图像有两个seqs,如:
let x = [(1,"x");(2,"y")]
let y = [(1, "xx", "xxx");(2,"yy","yyy")]
Run Code Online (Sandbox Code Playgroud)
元素是元组,但形状不同.
结果需要[(1, "x", "xx", "xxx");(2, "y", "yy", "yyy")].
元组中的第一个元素是这里的关键.
我写的代码使用的地图如下:
let x = [(1,"x");(2,"y")]
let y = [(1, "xx", "xxx");(2,"yy","yyy")]
let mapY = y |> Seq.map (fun (a,b,c) -> (a, (b, c))) |> Map.ofSeq
let r = [
for (k,v) in x do
let (v1,v2) = mapY |> Map.tryFind k |> Option.orElse (Some ("","")) |> Option.get
yield (k, v, v1, v2)
]
printfn "%A" r
Run Code Online (Sandbox Code Playgroud)
不那么优雅. …
当我需要手动open为F#源代码中使用的类型添加所有类型时,这非常烦人.特别是当我不熟悉我使用的引用时.
如果我忘记了命名空间,我打开对象浏览器,输入我正在使用的类名,等待1或2秒让VS完成冻结并获得我想要的命名空间.
我想要的就像是open namespace tip.我已经搜索了半个多小时,我甚至找不到有人问过类似的问题.
或者这都是我的错,我应该记住我在编码时使用的所有类型的命名空间???
我见过类似的问题:如何崩溃一个jvm和最短代码以提高SIGSEGv。
有一些Java代码可以生成SIGSEGV,例如:
final Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor();
unsafeConstructor.setAccessible(true);
final Unsafe unsafe = unsafeConstructor.newInstance();
System.out.println(unsafe.getAddress(0));
Run Code Online (Sandbox Code Playgroud)
并生成SIGSEGV类型的V(VM帧)。
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V [jvm.dll+0x1e2440]
Run Code Online (Sandbox Code Playgroud)
并且Crash in Compiled Code根据https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/crashes001.html进行。
我想知道是否仍然会产生类型化的J分段错误。
而且我已经看到了一些lib问题,例如JVM崩溃。(所以它表明可以手动生成?)
在阅读本书之前,对堆的引用就像:
let v: Vec<f64> = vec![0.0, 0.707, 1.0, 0.707];
let a: [f64; 4] = [0.0, -0.707, -1.0, -0.707];
let sv: &[f64] = &v;
let sa: &[f64] = &a;
Run Code Online (Sandbox Code Playgroud)
(来自Rust编程)
sv是对堆的引用,因此它指向堆中与v相同的地址。
但我从https://www.net.in.tum.de/fileadmin/bibtex/publications/theses/2018-ixy-rust.pdf阅读了一篇文章。
fn main(){
let s = String ::from("hello");
let r = &s;
let t = s;
println!("{}", r);
}
Run Code Online (Sandbox Code Playgroud)
(代码无法运行,因为它在移动后使用引用)

emmmm,r只是指向堆栈中的地址。是的,这是一个真正的引用,但rust中的引用是指针(对吗?)。
该图像与上面的图像相同(如果该值是堆栈分配的),并且更自然地解释了为什么移动后无法使用借位。
那么,哪个是科伦特呢?
我有一个名为抽象基类Token和一些子类型,如NumToken,StrToken.
我想把他们的实例放在同一个列表中.
我无法声明变量使用 let l = list<'a when 'a :> Token>
然后,我写
let extractToken<'a when 'a :> Token>(lineNum:int, line:string) : 'a list option =
let mutable result : 'a list = []
Run Code Online (Sandbox Code Playgroud)
它工作,但不能添加元素.result <- new NumToken(lineNum, value) :: result只是说它需要'a但是在这里NumToken
现在我可以使用new NumToken(lineNum, value) :> Token并声明Token list.
它看起来很丑陋(我知道fsharp不会自动投射......).
list<_ :> Token> 也不起作用,它只接受一个子类型.
谢谢你的帮助.