我必须在同一个类的不同方法中执行几个SQL查询.有没有办法让这些语句通用,我可以在所有方法中使用相同的con,statement变量来执行查询.
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/kamal","root","root");
Statement statement=con.createStatement();
Run Code Online (Sandbox Code Playgroud) 我是java的新手.我想插入从FileChooser数据库中选择的文件路径.但是当我尝试这样做时,路径在查询语句之前是正确的,并且在将其输入数据库之后,它将删除文件路径中存在的所有反斜杠.
filepath=f.getCanonicalPath();
// some database statements....
String query="insert into table1 values('" + filepath + "')";
Run Code Online (Sandbox Code Playgroud)
如果我选择的文件路径是:
"C:\用户\文档\ hello.txt的";
它将其插入:
"C:Usersdocumentshello.txt"