我試圖插入和檢索泰米爾(語言)values.But我越來越像??????
。JDBC - 如何在MySQL數據庫中插入和檢索泰米爾值
插入查詢一樣,
"INSERT INTO category VALUES (19, 'இந்தியா நாட்டின்','A');"
我的代碼一樣,
public static void main(String[] args) {
System.out.println("");
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = (Connection) DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
try{
Statement st = (Statement) conn.createStatement();
st.executeQuery("select categoryname from category");
ResultSet rs = st.getResultSet();
int count = 0 ;
while(rs.next()){
String name = rs.getString("categoryname");
System.out.println("Vlalue "+ name);
++count;
}
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
注:
我的配置,
OS : windows 7 (32 bit),
DataBase : MySQL 5.1,
JAVA : 1.7
您的連接看起來怎麼樣,你可以分享你的代碼嗎? –
@YCF_L,我加了我的基本示例代碼.. –