修复Json无法解析的问题,添加Upload的支持
String.Trim()方法能够去除字符串周围的不正常字符
This commit is contained in:
parent
b6e07fabdd
commit
1013b1de70
|
@ -34,6 +34,7 @@ class Handle implements Runnable
|
|||
}
|
||||
|
||||
String str = new String(buf,0,len);
|
||||
str=new String(str.trim());
|
||||
|
||||
System.out.println("String is: "+str);
|
||||
|
||||
|
@ -93,18 +94,40 @@ class Handle implements Runnable
|
|||
}
|
||||
break;
|
||||
case "getpart":
|
||||
break;
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case "getfull":
|
||||
break;
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case "upload":
|
||||
{
|
||||
UploadData up=null;
|
||||
try
|
||||
{
|
||||
up=gson.fromJson(str,UploadData.class);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("Incorrect Upload Data");
|
||||
continue;
|
||||
}
|
||||
|
||||
int ret=BookFloatingServer.Upload(up.getBookname(),up.getAuthor(),up.getContext(),up.getImageURL());
|
||||
pw.write("{'ret':'"+ret+"'}");
|
||||
pw.flush();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unknown Type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String reply="Connection is OK";
|
||||
pw.write(reply);
|
||||
pw.flush();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -126,6 +149,9 @@ class Handle implements Runnable
|
|||
public class BookFloatingServer
|
||||
{
|
||||
public static int Login(String Email,String Password) {
|
||||
|
||||
System.out.println("*Database*: Login with "+Email+" "+Password);
|
||||
|
||||
Connection conn = null;
|
||||
String url="jdbc:mysql://gameharbor.cn:3306/test";
|
||||
Statement stmt = null;
|
||||
|
@ -179,6 +205,8 @@ public class BookFloatingServer
|
|||
}
|
||||
|
||||
public static int Register(String Email,String Password,String Nickname,String School){
|
||||
System.out.println("*Database*:Register with "+Email+" "+Password+" "+Nickname+" "+School);
|
||||
|
||||
int upret=-1;
|
||||
Connection conn=null;
|
||||
String url="jdbc:mysql://gameharbor.cn:3306/test";
|
||||
|
@ -214,6 +242,52 @@ public class BookFloatingServer
|
|||
return upret;
|
||||
}
|
||||
|
||||
public static int Upload(String Bookname,String Author,String Context,String ImageURL){
|
||||
System.out.println("*Database*: Upload with "+Bookname+" "+Author+" "+Context+" "+ImageURL);
|
||||
int ret=-1;
|
||||
Connection conn=null;
|
||||
String url="jdbc:mysql://gameharbor.cn:3306/test";
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
try
|
||||
{
|
||||
conn=DriverManager.getConnection(url,"testuser","pwdtest");
|
||||
String sqlString=new String("INSERT into test.book VALUES (?,?,?,?,?)");
|
||||
stmt=conn.prepareStatement(sqlString,Statement.RETURN_GENERATED_KEYS);
|
||||
stmt.setString(1, Bookname);
|
||||
stmt.setString(2,Author);
|
||||
stmt.setString(3,"Provider Here");
|
||||
stmt.setString(4, ImageURL);
|
||||
stmt.setString(5, Context);
|
||||
ret=stmt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
try {
|
||||
if(stmt!=null) stmt.close();
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try{
|
||||
if(conn!=null) conn.close();
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static FetchInfo Fetch()
|
||||
{
|
||||
FetchInfo ff=null;
|
||||
return ff;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/*
|
||||
try {
|
||||
|
|
Reference in New Issue
Block a user